is around thirty times faster

Actually this dependent on the size of @patterns. When I benchmark them against each other i get more like a 100% speedup. Precalculating a hash of the patterns and then doing a hash lookup is infinitely faster.

Testing 100 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.09 usr + 0.02 sys = 1.11 CPU) @ 19 +103.70/s (n=21186) forex: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ 44 +43.24/s (n=4932) hash: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 16 +32288.34/s (n=1862441) Rate forex bigrex hash forex 4443/s -- -77% -100% bigrex 19104/s 330% -- -99% hash 1632288/s 36636% 8444% -- Testing 10000 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 83 +.80/s (n=89) forex: 2 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 42 +.68/s (n=44) hash: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 13 +97043.89/s (n=1464102) Rate forex bigrex hash forex 42.7/s -- -49% -100% bigrex 83.8/s 96% -- -100% hash 1397044/s 3273428% 1666934% -- Testing 100000 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.08 usr + 0.00 sys = 1.08 CPU) @ 7 +.42/s (n=8) forex: 2 wallclock secs ( 1.17 usr + 0.00 sys = 1.17 CPU) @ 4 +.27/s (n=5) hash: 2 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 12 +19285.16/s (n=1257083) Rate forex bigrex hash forex 4.27/s -- -43% -100% bigrex 7.42/s 74% -- -100% hash 1219285/s 28579944% 16429768% --

So id say you learned something new today too. :-) (use a hash...)


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: You learn something every day by demerphq
in thread You learn something every day by Jasper

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.