AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File read performance

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Kal_Torak



Joined: 06 Sep 2005
Posts: 36

PostPosted: Tue Mar 20, 2007 4:02 am    Post subject: File read performance Reply with quote

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
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 345
Location: Berlin / Germany

PostPosted: Tue Mar 20, 2007 4:19 am    Post subject: Reply with quote

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.

Wink
_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Mar 20, 2007 7:10 am    Post subject: Reply with quote

Also put this at the top of your script for some generic performance enhancements:
Code:
#NoEnv
SetBatchLines -1
Back to top
View user's profile Send private message
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Tue Mar 20, 2007 7:52 am    Post subject: Reply with quote

@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
View user's profile Send private message
Kal_Torak



Joined: 06 Sep 2005
Posts: 36

PostPosted: Tue Mar 20, 2007 1:12 pm    Post subject: Reply with quote

Sweet, now it takes about 200ms!
Thanks guys. Smile

WPM: 59.070. 27866.800 words in 471.760 minutes. Avg per session:4.484
Very Happy Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group