Any ideas why 'Errno' contants can be inlined but 'Socket' and 'Fcntl' constants can't?
use Benchmark qw( cmpthese ); use Errno qw( EAGAIN ); use Fcntl qw( O_NONBLOCK ); use Socket; # AF_INET BEGIN { our @const = qw( EAGAIN O_NONBLOCK AF_INET ); for my $const (@const) { eval "sub _$const () { ".&$const.' }'; die $@ if $@; } } our ($CONST_VALUE, $import, $inline, $scalar); for my $const (@const) { print "\n>>> Testing: $const\n"; $CONST_VALUE = &$const; cmpthese(5000000, { import => '$import = '.$const.';', inline => '$inline = _'.$const.';', scalar => '$scalar = $CONST_VALUE;', }); printf "Result: %d %d %d\n", $import, $inline, $scalar; } __END__ >>> Testing: EAGAIN Rate import scalar inline import 4716981/s -- -5% -19% scalar 4950495/s 5% -- -15% inline 5813953/s 23% 17% -- Result: 11 11 11 >>> Testing: O_NONBLOCK Rate import scalar inline import 904159/s -- -84% -84% scalar 5494505/s 508% -- -5% inline 5813953/s 543% 6% -- Result: 2048 2048 2048 >>> Testing: AF_INET Rate import inline scalar import 927644/s -- -84% -84% inline 5747126/s 520% -- -1% scalar 5813953/s 527% 1% -- Result: 2 2 2

In reply to Slow constants by powerman

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.