Wondering why the original benchmark didn't work as it should, lhoward said:
> (I think its some sort of quoting/scoping problem, > but I'm not sure exactly what).
It's a scoping problem. The quoted code (Grep2) isn't accessing the same %url hash as the other two pieces of code, which you could tell if you had warnings on. You get a warning about a "Useless use of list slice in void context" for that code.

Why aren't the others in void context? Grep is accessing the lexical %url because it's lexical to the file scope, and the Grep subroutine is defined in this file. And Grep3 (the third one) is accessing the same lexical %url because the anonymous sub acts as a closure (I think).

So Grep2 is looking at a different (not defined) %url, and is thus not actually a very good test in terms of benchmarking. :)


In reply to RE: Re: Algorithm Efficiency vs. Specialized Hardware? by btrott
in thread Algorithm Efficiency vs. Specialized Hardware? by Russ

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.