Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: 'constant' vs array (Ignore bad benchmarks: [mod://constant] arrays are (a little) faster!)by BrowserUk (Patriarch) |
on Jul 02, 2013 at 15:16 UTC ( [id://1042042]=note: print w/replies, xml ) | Need Help?? |
A couple of people have benchmarked constant arrays in this thread, but they've both made the same mistake: not checking what their code is doing and thus drawing bad conclusions. The problem is that this use constant ARRAY => qw(Title Section Subsection Class Category Degree Attempt CountOfCounts);; does not create an array. It creates a subroutine which returns an array as a list; which accounts for the inefficiency. On the other hand: This use constant ARRAY => [ qw(Title Section Subsection Class Category Degree Attempt CountOfCounts) ];; creates a subroutine that return a reference to the array, which you can then index efficiently (especially if you use enum for the indexes):
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.
In Section
Seekers of Perl Wisdom
|
|