in reply to Re^2: Initialsing file pointer in the middle of a file.
in thread Initialsing file pointer in the middle of a file.

What gave you that impression?

my $f; open($f,'<',"bigfile") or die "Could not open file\n"; my $i; while ($i++<1000000) { seek($f,10,0); seek($f,3000,0); }

This script needs 1.2 seconds on my machine, for 2 millions seeks. Time for the loop without anything in it is 0.275 seconds, so we are at 460 nanoseconds per seek

my $f; open($f,'<',"bigfile") or die "Could not open file\n"; my $i; my $g; while ($i++<1000000) { seek($f,10,0); $g= <$f>; seek($f,3000,0); } print length $g,"\n";

This script additionally does one million reads of a 2 character string and runs 3 seconds. That means 1800 nanoseconds is the minimal time for a read (from cache obviously, if the data is on disk multiply that time by 1000 or more)

Replies are listed 'Best First'.
Re^4: Initialsing file pointer in the middle of a file.
by sabertooth (Initiate) on Mar 17, 2010 at 05:26 UTC
    Hey jethro, Thanks a lot for giving me those statistics. I probably have a very good standing now to use seek function in my file. I initially thought using seek would be an overhead but then your statistics now tell me that it can be done in seconds. Thanks again.