Jump to content

How to parse faster?


Recommended Posts

Hi,

I would like to know if there is a way to speed up a parsing action of a text file (it takes me long long time to parse around 100000 lines)

Here is my simple script:

$LineNum=1

$file=FileOpen("c:\blabla.txt",0)

While 1

$Line=FileReadLine($file,$LineNum)

$x=StringMid($line,10,4)

If $x="xyz" Then exit

$LineNum=$LineNum+1

ToolTip($LineNum,0,0)

Wend

Thanks!!

Link to comment
Share on other sites

_FileReadToArray()

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Do as example says:

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend

FileClose($file)

since a FileReadLine($file, $line) causes the $file to be read from beginning. :o

Example just jumps to the next line. B)

Link to comment
Share on other sites

Do as example says:

since a FileReadLine($file, $line) causes the $file to be read from beginning. :o

Example just jumps to the next line. B)

That won't be any faster. _FileReadToArray() speeds up file processing quite a lot.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Hi!

The best solution would be pure C++, I think...

peethebee

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Link to comment
Share on other sites

Hi!

The best solution would be pure C++, I think...

peethebee

Sure, Assembly would be even faster, but then this would be the wrong forum to ask for help....

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Hi,

I would like to know if there is a way to speed up a parsing action of a text file (it takes me long long time to parse around 100000 lines)

Here is my simple script:

$LineNum=1

$file=FileOpen("c:\blabla.txt",0)

While 1

$Line=FileReadLine($file,$LineNum)

$x=StringMid($line,10,4)

If $x="xyz" Then exit

$LineNum=$LineNum+1

ToolTip($LineNum,0,0)

Wend

Thanks!!

2 things.... first, when would a 4 character string equal "xyz" ? second... another thing you may try, which sped up my commanator (turns a file into csv file) alot would be to read the file in and then put to an array by using stringsplit(). it does pretty much the same thing as the _filereadtoarray(), just another way to skin the cat. here's my revised commanator code for example. if you wanted to compare speed of the two methods, you could add a TimerInit() and TimerDiff() to each of the codes and run for the same data, i'd be kind of interested to see if i shouldn't change my code to make use of _FileReadToArray()

FileDelete("C:\output.txt")
dim $contents
$blah = FileRead("C:\sourceo.txt",filegetsize("C:\sourceo.txt"))
$output = FileOpen("C:\output.txt",1)
$contents = StringSplit($blah,@CRLF)
for $z = 1 to $contents[0]
$line = $contents[$z]
$newline = ""
        for $x = 1 to StringLen($line)
            $achar = StringMid($line,$x,1)
            if $achar = " " Then
                if StringRight($newline,1) = "," Then 
                    ContinueLoop
                Else
                    $newline = $newline & ","
                EndIf
            Else
                $newline = $newline & $achar
            EndIf
        Next
if StringLen($newline) then FileWriteLine($output,$newline)
Next
FileClose($output)
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...