Date: Sat, 23 Aug 2008 10:01:33 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Walt Pawley <walt@wump.org> Cc: Oliver Fromme <olli@lurza.secnetix.de>, freebsd-questions@freebsd.org Subject: Re: sed/awk, instead of Perl Message-ID: <48AFD1ED.5070800@infracaninophile.co.uk> In-Reply-To: <p0624080cc4d504c10465@[10.0.0.10]> References: <200808220759.m7M7xuh0047625@lurza.secnetix.de> <p0624080cc4d504c10465@[10.0.0.10]>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig86B0024FDAB8CBABBAE93E8C Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Walt Pawley wrote: > At 9:59 AM +0200 8/22/08, Oliver Fromme wrote: >=20 >> - 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? >=20 > 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: >=20 > 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 >=20 > real 0m10.800s > user 0m10.580s > sys 0m0.250s > wump$ time perl -pe 's/ .*//' Desktop/klog > kadr2 >=20 > real 0m0.975s > user 0m0.700s > sys 0m0.270s > wump$ cmp kadr1 kadr2 > wump$ >=20 > 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. >=20 > 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 --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig86B0024FDAB8CBABBAE93E8C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAkiv0fMACgkQ8Mjk52CukIyHWQCgioniIeKcaaqnoASNUMTDs7cD zmQAniqb2huOqDPGxELh9G65w3qLoUbH =NXLU -----END PGP SIGNATURE----- --------------enig86B0024FDAB8CBABBAE93E8C--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48AFD1ED.5070800>