Interestingly, if you throw a literal value in the mix, as done below, you will find that the literal is even usually a hair slower than a my variable. I'd be very curious to know why that is:
#!/usr/bin/perl -w use strict; use vars qw(*const_alias $const_local); use Benchmark qw(cmpthese); local *const_alias = \100; my $const_ref = \100; local $const_local = 100; my $const_my = 100; sub CONST_SUB () { 100 }; use constant CONST_MOD => 100; print "mod[".CONST_MOD."]\nsub[".CONST_SUB."]\n" ."my[$const_my]\nlocal[$const_local]\n" ."ref[$$const_ref]\nalias[$const_alias]\n"; # run iteratively within the sub to get a less skewed # result - that's my theory anyway :-) my $iter = 500; my $t; cmpthese (-5, { CMod => sub { $t = CONST_MOD for 1..$iter }, CSub => sub { $t = CONST_SUB for 1..$iter }, CMy => sub { $t = $const_my for 1..$iter }, CLocal => sub { $t = $const_local for 1..$iter }, CRef => sub { $t = $$const_ref for 1..$iter }, CAlias => sub { $t = $const_alias for 1..$iter }, CLit => sub { $t = 100 for 1..$iter }, }); ### RESULTS (repeatable this time :) ### Rate CRef CAlias CLocal CSub CLit CMod CMy CRef 3735/s -- -9% -9% -10% -11% -11% -13% CAlias 4088/s 9% -- -0% -2% -3% -3% -5% CLocal 4088/s 9% 0% -- -2% -3% -3% -5% CSub 4172/s 12% 2% 2% -- -1% -1% -3% CLit 4208/s 13% 3% 3% 1% -- -0% -2% CMod 4210/s 13% 3% 3% 1% 0% -- -2% CMy 4293/s 15% 5% 5% 3% 2% 2% --
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

In reply to Re(4): my $var; vs. use constant VAR = ''; by MeowChow
in thread my $var = ''; vs. use constant VAR => ''; by antihero

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.