Re: sed/awk, instead of Perl



Walt Pawley wrote:
At 9:59 AM +0200 8/22/08, Oliver Fromme wrote:

- The perl command you wrote above is pretty much a sed
command anyway (except you incorrectly used non-portable
regular expression syntax). Why use perl to execute a
sed command?

At the risk of beating this to death, I just happened to
stumble on a real world example of why one might want to use
Perl for sed-ly stuff. I wanted to pull off the accessor's
address from each line of an Apache access log file. So, I
figured after this discussion that sed was the way to go. Then
I got curious and did the following:

wump$ ls -l Desktop/klog
-rw-r--r-- 1 wump 1001 52753322 22 Aug 16:37 Desktop/klog
wump$ time sed "s/ .*//" Desktop/klog > kadr1

real 0m10.800s
user 0m10.580s
sys 0m0.250s
wump$ time perl -pe 's/ .*//' Desktop/klog > kadr2

real 0m0.975s
user 0m0.700s
sys 0m0.270s
wump$ cmp kadr1 kadr2
wump$

Why disparity in execution speed? Beats me, but my G5's fans
started to take off running the sed command. I don't think the
Perl command took long enough to register thermally. Curious.

FWIW: I did this with an older version of Mac OS X, rather
FreeBSD so it could easily not show the same results if I moved
the log file to a FreeBSD box and did it there.

Careful now. Have you accounted for the effect of the klog file
being cached in VM rather than having to be read afresh from disk?
It makes a very big difference in how fast it is processed.

In order to get meaningful data for this sort of test you should
do a dummy run or two of each command in fairly quick succession,
and then repeat your test runs a number of times and look at the
average and standard deviation of the execution times. You'll often
see "Student's T test" mentioned -- that's a statistical test for
assessing if results calculated from a limited number of samples
represent different underlying distributions. It sounds horribly
complicated, but nowadays we have computers to do all the difficult
adding up and the result is just a number that tells you how well
your supposition (that command 'a' is faster than command 'b') is
supported by your results. There's a neat little script somewhere
that will automate that, and even give you an ascii graph output,
but I cannot for the life of me remember what it's called. Sorry.

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
Kent, CT11 9PW

Attachment: signature.asc
Description: OpenPGP digital signature



Relevant Pages

  • Re: Most dependable way to run system commands
    ... Eventually I'd like to bring the execution of a few system commands ... specific execution issue (it dealt more with executing Perl code)). ... Unix and many similar systems, the exit status is an integer, with 0 ... variable after running a command via system or backticks. ...
    (perl.beginners)
  • Re: Wait for background processes to complete
    ... To be able to execute commands in the background and wait for their ... The documentation I am referring to is http://perldoc.perl.org/. ... You can run a command in the background with: ... There is a general problem with perl documentation: ...
    (comp.lang.perl.misc)
  • Re: Perl For Amateur Computer Programmers
    ... >professional computer programmers could use with the same ease as Basic. ... >Perl For Amateur Computer Programmers ... Also, taking into account that you're appealing to "scientists", it ... Also, as a side note, you seem to use the noun "command" in a naive ...
    (comp.lang.perl.misc)
  • Obtaining complete Unix command line that evoked script as string
    ... If there is a more appropriate list for this, let me know; the other perl lists I've seen seem to specialised for this. ... Note this is not just the arguments of the call to the script, but everything including pipes and redirects, etc., e.g. ... Ideally the perl interpreter would grab the complete command line as its evoked and I'd access this via a variable. ...
    (perl.beginners)
  • Re: Memory: measuring 5 limitations
    ... > This will give you information about the execution of the script. ... > Perl, but it will give you more information than what you're getting ... Yeah I have shell access and I can execute the time command. ... However the output format looks great and I believe that it is what I ...
    (comp.lang.perl.misc)