> which is faster?
> 
> Randal's suggestion:
> 
> my @result = <*.jpg>;
> 
> or variations on:
> 
> @files = grep /jpg/i, readdir DIR;
> 

Try this...

use Benchmark;

opendir (DH, ".") or die;

timethese(50000, {
        'Randals' => q{my @result = <*.jpg>},
        'variations' => q{my @result = grep /\.jpg$/i, readdir DH}
});

closedir(DH)

and change the 50000 to whatever you need to so that you get a meaningfull
time.  I got

Benchmark: timing 50000 iterations of Randals, variations...
   Randals: 79 wallclock secs (28.94 usr + 49.99 sys = 78.93 CPU) @ 633.46/s
(n=50000)
variations:  0 wallclock secs ( 0.03 usr +  0.00 sys =  0.03 CPU) @
1666666.67/s (n=50000)
            (warning: too few iterations for a reliable count) 

Peter C.

Reply via email to