in reply to Using Perl saves time....

localhost:/usr/share/doc$ time perl -e 'print scalar(()=glob"*"),$/' 1164 real 0m0.045s user 0m0.040s sys 0m0.000s


Replies are listed 'Best First'.
Re^2: Using Perl saves time....
by greenFox (Vicar) on Jul 19, 2005 at 08:55 UTC

    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

      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