You pays your money and takes your choice:

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; use constant { X => 0, Y => 1, Z => 2, P => 3, Q => 4, }; use Readonly; Readonly::Hash my %Fields => { X => 0, Y => 1, Z => 2, P => 3, Q => 4, }; sub prioritisedSort1 { return $a->[ P ] <=> $b->[ P ] or $a->[ Z ] <=> $b->[ Z ] or $a->[ Y ] <=> $b->[ Y ] or $a->[ X ] <=> $b->[ X ] or $a->[ Q ] <=> $b->[ Q ]; } sub prioritisedSort2 { return $a->[$Fields{P}] <=> $b->[$Fields{P}] or $a->[$Fields{Z}] <=> $b->[$Fields{Z}] or $a->[$Fields{Y}] <=> $b->[$Fields{Y}] or $a->[$Fields{X}] <=> $b->[$Fields{X}] or $a->[$Fields{Q}] <=> $b->[$Fields{Q}]; } our $N ||= 1e5; my @AoA1 = map { [ map{ int rand $_ } 1000, 100, 10, 500, 50 ] } 1 .. $N; my @AoA2 = map{ [ @$_ ] } @AoA1; my( @sorted1, @sorted2 ); cmpthese -1, { constant => sub{ @sorted1 = sort prioritisedSort1 @AoA1 }, Readonly => sub{ @sorted2 = sort prioritisedSort2 @AoA2 }, }; print "\nFirst and last 5 for constant"; print "[@$_]" for @sorted1[ 0 .. 4 ], [ qw[ - - - - - ] ], @sorted1[ -5 .. -1 ]; print "\nFirst and last 5 for Readonly"; print "[@$_]" for @sorted2[ 0 .. 4 ], [ qw[ - - - - - ] ], @sorted2[ -5 .. -1 ]; __END__ C:\test>junk8 -N=1e2 Rate Readonly constant Readonly 137/s -- -96% constant 3459/s 2427% -- First and last 5 for constant [226 44 0 8 3] [425 64 7 10 2] [790 25 8 20 27] [461 37 0 27 47] [151 51 3 31 35] [- - - - -] [734 15 9 482 6] [90 40 2 489 5] [957 21 9 491 45] [17 99 3 494 44] [585 50 7 495 22] First and last 5 for Readonly [226 44 0 8 3] [425 64 7 10 2] [790 25 8 20 27] [461 37 0 27 47] [151 51 3 31 35] [- - - - -] [734 15 9 482 6] [90 40 2 489 5] [957 21 9 491 45] [17 99 3 494 44] [585 50 7 495 22]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^2: OOP - Constant Vs. Subroutine by BrowserUk
in thread OOP - Constant Vs. Subroutine by 2xlp

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.