Sign in to follow this  
Followers 0
jennico

hint to speed up FileRead function

2 posts in this topic

#1 ·  Posted (edited)

hi,

i just want to give a hint how to speed up the fileread function drastically on large files (e.g. .dat).

instead of reading in the whole file you can create a loop reading in just a defined number of characters. the fileread function continues to read in characters beginning with the last character read before +1.

for example:

you have a large .dat file (several mbs) and you know that you don't need the first 162309 characters, but then you want to analyze the rest of the file in parts of 1024 characters (like splitting a database).

instead of reading in the whole file and then splitting it by stringmid() you can do it like that and save a lot of time:

$file=FileOpen("test.dat",0)
    $a=FileRead($file,162309); the first 162309 characters to be ignored
    While 1
        $a=FileRead($file,1024); fileread in steps of 1024 characters
      ; do what you like to do
    Wend    ; next 1024 characters
    FileClose($file)
    Exit

in this way i was able to read in, split and rewrite a 5 mb data file within 3 seconds (before 20 minutes).

i noticed that this feature is not mentioned in help file.

and i am sorry if this hint was mentioned before.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0