>>>>> "iansmith" == iansmith <[EMAIL PROTECTED]> writes:
iansmith> On Fri, 8 Jun 2001, Richard Hulse wrote:
>> Since someone raised the general question of differences, which is faster?
>> my @result = <*.jpg>;
>> or variations on:
>> @files = grep /jpg/i, readdir DIR;
iansmith> use Benchmark;
iansmith> timethese(10000, {
iansmith> 'Glob' => sub { my @result = <*.jpg>; },
iansmith> 'Read' => sub { opendir(DIR,"."); @files = grep /jpg/i, readdir DIR; }, });
iansmith> Benchmark: timing 10000 iterations of Glob, Read...
iansmith> Glob: 78 wallclock secs (49.36 usr + 27.43 sys = 76.79 CPU)
iansmith> @ 130.23/s (n=10000)
iansmith> Read: 32 wallclock secs (27.71 usr + 3.69 sys = 31.40 CPU)
iansmith> @ 318.47/s (n=10000)
iansmith> Looks like readdir() is the winner, at least on my system.
iansmith> This was done in a directory of 1000 jpg images.
iansmith> The times certianly look right... the glob uses a ton of system time, and
iansmith> the readdir uses a ton of user time, just as one would expect.
Was this on 5.6 or 5.6.1, where the glob is internalized, or on 5.5 or
earlier, where glob called an external process?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!