Not optimisations, errors.
#! perl -slw
use strict;
#use sort
use Benchmark ();
sub argless { $a cmp $b }
sub proto($$) { $_[0] cmp $_[1] }
sub args { $_[0] cmp $_[1] }
my @array = qw(
Perl may be copied only under the terms of either the Artistic Lice
+nse or the
GNU General Public License, which may be found in the Perl 5 source
+ kit.
);
Benchmark::cmpthese(-1, {
inline => q[ sort { $a cmp $b } @array; ],
argless => q[ sort argless @array; ],
proto => q[ sort proto @array; ],
args => q[ sort { args($a, $b) } @array; ],
});
__END__
P:\test>410266
Possible attempt to separate words with commas at P:\test\410266.pl li
+n
Name "main::b" used only once: possible typo at P:\test\410266.pl line
Name "main::a" used only once: possible typo at P:\test\410266.pl line
Useless use of sort in void context at (eval 4) line 1.
...
Useless use of sort in void context at (eval 182) line 1.
Rate argless proto inline args
argless 6619798/s -- -2% -8% -19%
proto 6748958/s 2% -- -6% -18%
inline 7189879/s 9% 7% -- -12%
args 8216252/s 24% 22% 14% --
Examine what is said, not who speaks.
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail
"Time is a poor substitute for thought"--theorbtwo
"Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.