G
George Mpouras
I have a file already open (in fact could be 100s). How can I get the
size faster
1) -f ...
2) seek FILE, 0, 2; tell FILE;
size faster
1) -f ...
2) seek FILE, 0, 2; tell FILE;
1) -sI have a file already open (in fact could be 100s). How can I get the
size faster
1) -f ...
2) seek FILE, 0, 2; tell FILE;
George Mpouras said:Στις 21/1/2014 12:08, ο/η George Mpouras ÎγÏαψε:
Marius Gavrilescu said:use Benchmark;
This code:
#!/usr/bin/perl -w
use Benchmark qw/cmpthese/;
open FILE, '<file';
cmpthese(10000000, {
-s => sub { -s FILE },
seektell => sub { seek FILE, 0, 2; tell FILE },
})
produces this output over here (Debian amd64, perl v5.18.2):
Rate seektell -s
seektell 3952569/s -- -48%
-s 7575758/s 92% --
So -s is almost twice as fast as seektell.
If the seek is only done once, the result becomes:
Rate -s seektell
-s 7022472/s -- -82%
seektell 39370079/s 461% --
So tell is significantly faster than -s, but the combination of
seek+tell is slower.
Ben Morrow said:They may not move the (OS) file pointer, but they will still make two
lseek(2) calls, which is what takes the time. (Moving the file pointer
from within the kernel is obviously entirely trivial.) Perl doesn't
know, until the OS tells it, that the file hasn't changed length since
the last time it found the end.
This will do four lseek(2)s per iteration vs one fstat(2); not exactly a
fair comparison.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.