Actually, to my surprise, simply sticking an ID number in the refered-to object (it's an array) and dereferencing it is fastest. Here are the numbers:
Benchmark: running ID Field, Numeric, Refaddr, String for at least 3 C +PU seconds... ID Field: 4 wallclock secs ( 3.43 usr + 0.03 sys = 3.46 CPU) @ 10 +44124.57/s (n=3612671) Numeric: 4 wallclock secs ( 3.34 usr + 0.04 sys = 3.38 CPU) @ 98 +9664.50/s (n=3345066) Refaddr: 5 wallclock secs ( 3.08 usr + 0.03 sys = 3.11 CPU) @ 91 +2330.23/s (n=2837347) String: 4 wallclock secs ( 3.09 usr + 0.04 sys = 3.13 CPU) @ 74 +7332.27/s (n=2339150)
Rate String Refaddr Numeric ID Field String 747332/s -- -18% -24% -28% Refaddr 912330/s 22% -- -8% -13% Numeric 989664/s 32% 8% -- -5% ID Field 1044125/s 40% 14% 6% --
And here's the code that did the Benchmark:
#!perl -w use strict; use Benchmark qw(:all); use Scalar::Util qw(refaddr); my $r = [0]; sub string { pack("A", "$r"); } sub numeric { pack("J", $r+0); } sub addr { pack("J", refaddr $r); } sub field { pack("J", $r->[0]); } my $result = timethese(-3, { String => \&string, Numeric => \&numeric, Refaddr => \&addr, "ID Field" => \&field, }); cmpthese($result);

In reply to A benchmark by Jeffrey Kegler
in thread Unique numeric ID for reference? by Jeffrey Kegler

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.