/users/mfiresto/experiment)perl timeclean.pl
Benchmark: timing 500000 iterations of myway, regexpway...
myway: 24 wallclock secs (24.11 usr + 0.00 sys = 24.11 CPU)
regexpway: 70 wallclock secs (67.60 usr + 0.00 sys = 67.60 CPU)

/users/mfiresto/experiment)perl -v
This is perl, version 5.005_03 built for sun4-solaris

/users/mfiresto/experiment)uname -a
SunOS XXXX 5.5.1 Generic_103640-28 sun4u sparc SUNW,Ultra-5_10

/users/mfiresto/experiment)perl timeclean.pl
Benchmark: timing 500000 iterations of myway, regexpway...
myway: 19 wallclock secs (18.44 usr + 0.00 sys = 18.44 CPU)
regexpway: 40 wallclock secs (40.65 usr + 0.00 sys = 40.65 CPU)

/users/mfiresto/experiment)perl -v
This is perl, version 5.005_03 built for i686-linux

/users/mfiresto/experiment)uname -a
Linux XXXX 2.0.36 #1 Tue Dec 29 13:11:13 EST 1998 i686 unknown

And, just for something completely different, I thought to try this against perl 5.6.0 and the results are very similar.

UPDATE
It has dawned on me while reading this thread that this exposes one of the dangers on relying too heavily on Benchmark to determine the best algorithm. Notice the man pages for $& state it will impose a serious penalty on all other regex. In normal code for me, this would indeed be disasterous because I use a lot of regex.

However, in the Benchmark code, there are only two regex statements used. With a bit of cleverness, I was able to remove the $& reference and received no real speed improvement. That is because Benchmark does not run in real-world conditions. We all tend to extract the part we wish to test and just run that. In this case, it may not work. If we were to test this code in a real world situation, we may see a difference.

Then again, we may not. According to some quick experiments, Benchmark cannot reliably measure the first method in less than ( approximately ) 9500 iterations. Personally, I have not seen a CGI parameter that contains 9500 'escaped' characters. Do the benchmarks at this point really mean anything?

Shouldn't we be more concerned with good code? How about which one is easier to maintain? How about which one is more Perlish? Which one fits the coder better?

Wow. Sorry to rant. I have been thinking about this too much.

Mik


In reply to RE: RE: RE: form parsing, hex, HTML formatting by mikfire
in thread form parsing, hex, HTML formatting by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.