You could also force stringification to get an even bigger speedup compared to calling pack on every hash access (if that's what you're doing), e.g. $x = "$x" or $_="$_" for @values;. Update: Added the pre-packed test with $p, which surprisingly is still not as fast as the stringified float $y. Update 2: By giving each test case its own hash instead of using one hash for all tests, now the test cases "y" and "p" perform roughly the same, as I would have originally expected (Update 3: However, across multiple runs of this benchmark, "y" still tends to outperform "p", often significantly). Update 4: If you set $x = 42.123456789, then "p" consistently outperforms "y", so I'd guess it has to do with the hash key length. (last update, I promise ;-) )

use Benchmark qw/ cmpthese /; my $x = 42.0; my $y = "$x"; my $p = pack 'F', $x; my (%h1,%h2,%h3,%h4); cmpthese( -1, { F => sub { $h1{ pack 'F', $x } = 1 }, s => sub { $h2{ $x } = 1 }, y => sub { $h3{ $y } = 1 }, p => sub { $h4{ $p } = 1 }, }); __END__ Rate s F p y s 4032984/s -- -64% -84% -84% F 11327209/s 181% -- -54% -56% p 24707825/s 513% 118% -- -5% y 25997751/s 545% 130% 5% --

In reply to Re: Any reason NV is not marked as POK when accessed as string? (updated) by haukex
in thread Any reason NV is not marked as POK when accessed as string? by vr

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.