Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: cat vs. file handle speed?

by Malkavian (Friar)
on Mar 30, 2001 at 15:49 UTC ( [id://68338]=note: print w/replies, xml ) Need Help??


in reply to cat vs. file handle speed?

Quick answer:
In an ideal world (and most cases), Perl will beat cat in a file read.
Caveat:
If you're running on Linux, this isn't the case, and cat is actually faster. See the enlightened node by tye on this subject here.
A minor work around (read ugly hack) to get Linux to work faster was to use a read statement, and break down the block into lines using a reader object. Seems to work for Linux, but will seriously slow down other OSes.
Malk

Replies are listed 'Best First'.
(tye)Re: cat vs. file handle speed?
by tye (Sage) on Mar 30, 2001 at 22:16 UTC

    Well, my analysis applies if cat uses "stdio.h" to read the file (which probably depends on the breed of cat that you have).

    But that doesn't matter in this case because even if cat is faster than Perl, Perl would still have to read the output from cat. So X+Y is always bigger than just Y (since a process can't consume negative resources), whether X<Y or Y<X.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found