Jump to content

ARRAY questions....


kart442
 Share

Recommended Posts

I have 4 files being read to Arrays....The more elements I add the slower the script runs.

Is there some other way so the script doesn't slow down?

Have you timed the various functional parts of your script (TimerInit/TimerDiff)? I suspect four calls to _FileReadToArray() are not the slow part, but your loop logic using the arrays.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

OK I see about the exitloops I'll try it without them but prefer to use them.

If there is quicker way other that _FileReadToArray please let know.

You're obviously trying to find something in these files, and they must be pretty hefty.

The steps that _FileReadToArray() takes are probably along these lines.

1. FileRead: - Read entire file (pretty dog gone fast)

2. StringSplit - StringStripCR @LF: - Strip all carriage returns and split the file for each line with Line Feed (pretty dog gone fast)

3. Return Array

Now the above mentioned takes next to no time at all... so as PsaltyDS said... the fault is in your end, for 1 of 2 reasons.

1. These files are monsterous.

2. Your loop you are using to parse the files, find your string, manipulate the string, twiddle your thumbs, count your toes, then finally return the value is probably not soundly set up.

If it is one string you are trying to find... and you have the guts to learn it (On your own through the search engine here and google), StringRegExp() may prove to be a much faster solution to parsing line by line in each file (You'd still have to use FileRead() of course).

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

OK I see about the exitloops I'll try it without them but prefer to use them.

If there is quicker way other that _FileReadToArray please let know.

You don't have to do without anything, just add some TimerInit's and TimerDiff's to show the time taken for each part: 1. _FileReadToArray() and 2. Completing your (search?) loop.

That will tell you what to focus on for improvement. And I'm still betting on you loop to manipulate the array AFTER the _FileReadToArray() is done.

#include <array.au3>
#include <file.au3>

; Four almost identical 20KB log files used for test
Dim $avFiles = _ArrayCreate("C:\Temp\Test1.txt", "C:\Temp\Test2.txt", "C:\Temp\Test3.txt", "C:\Temp\Test4.txt")

Dim $iReadTime = 0, $iSortTime = 0, $iTime, $avData, $iCount, $sMsg
$iCount = UBound($avFiles)
For $n = 0 To UBound($avFiles) - 1 
    $iTime = TimerInit()
    If _FileReadToArray($avFiles[$n], $avData) Then
        $iReadTime += TimerDiff($iTime)
        $iTime = TimerInit()
        _ArraySort($avData, 0, 1)
        $iSortTime += TimerDiff($iTime)
    Else
        $iCount -= 1
        MsgBox(16, "Error", "Error reading file to array: " & $avFiles[$n])
    EndIf
Next

If $iCount Then
    $sMsg = "Avg time for _FileReadToArray() = " & Round($iReadTime / $iCount, 1) & "ms" & @CRLF & _
            "Avg time for _ArraySort() = " & Round($iSortTime / $iCount, 1) & "ms"
    MsgBox(64, "Results", $sMsg)
Else
    MsgBox(16, "Error", "None of the file operations were successfull = no stats.")
EndIf

In this test, _FileReadToArray() took about 2.6ms avg, and the sort took 90.2ms avg.

Test your code in a similar fashion. Don't guess about what needs optimization.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...