Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl/grep speed comparison

by Sixtease (Friar)
on Nov 17, 2007 at 21:44 UTC ( [id://651453]=perlquestion: print w/replies, xml ) Need Help??

Sixtease has asked for the wisdom of the Perl Monks concerning the following question:

WTF is wrong with grep?
$ time grep '.' myfile real 5m53.088s
$ time perl -ne '/./ and print' myfile real 0m0.387s

Replies are listed 'Best First'.
Re: Perl/grep speed comparison
by tuxz0r (Pilgrim) on Nov 17, 2007 at 22:01 UTC
    I don't see the kind of difference on my machine (G4 iBook running Mac OS X 10.5) as you do (I'm using a 30K file of all 'x's):
    radar:~ datchley$ time grep "." myfile >/dev/null real 0m0.989s user 0m0.821s sys 0m0.078s radar:~ datchley$ time perl -ne '/./' myfile >/dev/null real 0m0.020s user 0m0.006s sys 0m0.013s
    How big is your file, what machine?

    ---
    echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
    Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.

Re: Perl/grep speed comparison
by eserte (Deacon) on Nov 17, 2007 at 22:26 UTC
    On my machine (an Athlon64 with amd64-freebsd) grep is always faster than perl. Using an 8MB test file:
    $ time perl5.10.0 -ne '/./ and print' /boot/kernel/kernel > /dev/null 0.070u 0.015s 0:00.09 88.8% 1490+1246k 0+0io 0pf+0w $ time grep -a '.' /boot/kernel/kernel > /dev/null 0.026u 0.000s 0:00.03 66.6% 114+1056k 0+0io 0pf+0w
Re: Perl/grep speed comparison
by Sixtease (Friar) on Nov 17, 2007 at 22:47 UTC
    Guess I'll have to ask in the Gentoo forums then. But well... aliasing grep to pcregrep removed this slowness and I can use the regexes I love. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://651453]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found