in reply to system calls vs perl functions: Which should be faster in this example?

I would expect the I/O of special-purpose utilities to be faster than Perl's processing. However, you're slinging the data around more than you need to. First you read the whole mess into an array, and then you grep it into another array before simply counting the number of elements and throwing it all away.

Try redefining lsof_perl like so:

'lsof_perl' => sub { print scalar(grep(/file_a/, `$lsofcmd +3`)); },
You should get somewhat better results.

Caution: Contents may have been coded under pressure.
  • Comment on Re: system calls vs perl functions: Which should be faster in this example?
  • Download Code

Replies are listed 'Best First'.
Re^2: system calls vs perl functions: Which should be faster in this example?
by machinecraig (Monk) on Dec 05, 2005 at 20:18 UTC
    What you say about specialized utilities makes sense - also, good point about needless moving around of the lsof output. Thanks!