in reply to Re: Using Perl saves time....
in thread Using Perl saves time....

Your code is slow too, you need a suitably large directory to test properly-

$ time perl -e 'print scalar(()=glob"*"),$/' 136631 real 0m4.810s user 0m3.340s sys 0m1.320s $ time perl -le 'opendir f, $ARGV[0] or die $!;++$c while readdir f; p +rint $c' . 136633 real 0m0.440s user 0m0.400s sys 0m0.040s

--
Murray Barton
Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Replies are listed 'Best First'.
Re^3: Using Perl saves time....
by sh1tn (Priest) on Jul 19, 2005 at 10:47 UTC
    You are right - glob is slower than readdir.
    My point is the short one-liner. Otherwise:
    # time ls | wc -l 99999 real 0m1.850s user 0m1.590s sys 0m0.210s # time perl -e '@_ = glob"*";print$#_' 99998 real 0m1.462s user 0m0.880s sys 0m0.570s # the best alternative: # time perl -MIO::Dir -e '@_ = IO::Dir->new(".")->read;print$#_' 100000 real 0m0.680s user 0m0.570s sys 0m0.100s