 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Kal_Torak
Joined: 06 Sep 2005 Posts: 36
|
Posted: Tue Mar 20, 2007 4:02 am Post subject: File read performance |
|
|
I'm running this code, and I'm wondering if there is any way to speed it up.
The file has over 6000 lines and will continue to grow, and it's now taking over 6 seconds to process the file.
Any performance changes I could make?
| Code: |
WordsTyped=0
TimeTaken=0
i = 0
Loop
{
i++
FileReadLine, line, C:\TypingLog.txt, %i%
if ErrorLevel
break
needle=|
pipePos := InStr(line,"|",0,0)
StringLeft, Words,line, pipePos
StringLen, len, line
StringRight, Time,line,len-pipePos
WordsTyped+=Words
TimeTaken+=Time
}
|
I tried stripping out the string manip functions, but that doesn't make a noticable difference. |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 345 Location: Berlin / Germany
|
Posted: Tue Mar 20, 2007 4:19 am Post subject: |
|
|
http://www.autohotkey.com/docs/commands/LoopReadFile.htm
| Quote: | | A file-read loop is useful when you want to operate each line contained in a text file, one at a time. It performs better than using FileReadLine because: 1) the file can be kept open for the entire operation; and 2) the file does not have to be re-scanned each time to find the requested line number. |
 _________________ nick
denick @ http://de.autohotkey.com/forum/ |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Mar 20, 2007 7:10 am Post subject: |
|
|
Also put this at the top of your script for some generic performance enhancements:
| Code: | #NoEnv
SetBatchLines -1 |
|
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Tue Mar 20, 2007 7:52 am Post subject: |
|
|
@Kal_Torak,
Try something along these lines.
| Code: |
#NoEnv ; <<<
SetBatchLines -1 ; <<<
WordsTyped=0
TimeTaken=0
i = 0
needle=| ; <<<
FileRead, MFile,C:\TypingLog.txt ; <<<
Loop,parse,MFile,`n ; <<<
{
Line := A_LoopField ; <<<
i++
;;; FileReadLine, line, C:\TypingLog.txt, %i%
;;; if ErrorLevel
;;; break
;;; needle=|
pipePos := InStr(line,"|",0,0)
StringLeft, Words,line, pipePos
StringLen, len, line
StringRight, Time,line,len-pipePos
WordsTyped+=Words
TimeTaken+=Time
}
|
Should be faster, having loaded the complete file into memory first ! _________________ Simple ideas lie within reach, only of complex minds |
|
| Back to top |
|
 |
Kal_Torak
Joined: 06 Sep 2005 Posts: 36
|
Posted: Tue Mar 20, 2007 1:12 pm Post subject: |
|
|
Sweet, now it takes about 200ms!
Thanks guys.
WPM: 59.070. 27866.800 words in 471.760 minutes. Avg per session:4.484
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|