(Edit: I agree with tye, it's not the difference between string, int, or ref compares that's going to make or break the script. But it was still a fun benchmark. Oh, and 10 or 15% over 3 seconds is fairly consistently repeatable. 5% would be "noise". :))

Interesting that you wind up with strings fastest. I wind up with numbers fastest, hands down, using 5.6.1 on Cygwin.

I agree that this is a micro (or nano:)) optimization; I was just responding to his query as to why the ref compare was so slow in his code.

$ perl ref_cmp.pl Benchmark: running numbers 2, numbers 4, qrefs 2, qrefs 4, refs 2, ref +s 4, strings 2, strings 4, each for at least 3 CPU seconds... numbers 2: 4 wallclock secs ( 3.08 usr + 0.00 sys = 3.08 CPU) @ 74 +0880.04/s (n=2278947) numbers 4: 5 wallclock secs ( 3.18 usr + 0.03 sys = 3.21 CPU) @ 49 +7290.48/s (n=1593816) qrefs 2: 3 wallclock secs ( 3.08 usr + -0.01 sys = 3.07 CPU) @ 64 +0138.26/s (n=1967785) qrefs 4: 4 wallclock secs ( 3.02 usr + 0.00 sys = 3.02 CPU) @ 42 +8683.86/s (n=1296340) refs 2: 4 wallclock secs ( 3.11 usr + 0.01 sys = 3.12 CPU) @ 41 +4780.49/s (n=1292456) refs 4: 5 wallclock secs ( 3.02 usr + 0.01 sys = 3.03 CPU) @ 28 +0746.21/s (n=851784) strings 2: 3 wallclock secs ( 3.06 usr + 0.02 sys = 3.08 CPU) @ 64 +2239.02/s (n=1974885) strings 4: 4 wallclock secs ( 3.11 usr + 0.01 sys = 3.12 CPU) @ 47 +6537.87/s (n=1484892) Rate refs 4 refs 2 qrefs 4 strings 4 numbers 4 qrefs 2 s +trings 2 numbers 2 refs 4 280746/s -- -32% -35% -41% -44% -56% + -56% -62% refs 2 414780/s 48% -- -3% -13% -17% -35% + -35% -44% qrefs 4 428684/s 53% 3% -- -10% -14% -33% + -33% -42% strings 4 476538/s 70% 15% 11% -- -4% -26% + -26% -36% numbers 4 497290/s 77% 20% 16% 4% -- -22% + -23% -33% qrefs 2 640138/s 128% 54% 49% 34% 29% -- + -0% -14% strings 2 642239/s 129% 55% 50% 35% 29% 0% + -- -13% numbers 2 740880/s 164% 79% 73% 55% 49% 16% + 15% --

--
Mike

In reply to Re: (tye)Re: speed of comparisons of things by RMGir
in thread speed of comparisons of things by John M. Dlugosz

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.