ikegami, I know you already know it, but reading your post somebody could thing that using the your GRT code is a good idea because it is the faster solution when actually it is not!
It is not good because using substr() to extract the sorting keys is very weak. If for instance, the file names extensions are changed, it will extract incorrect keys and, what is worst, without reporting any warning or error to the user!
Even if slower, using a regular expression to extract the keys is probably the best solution.
In any case, there is a faster (not recommendable either) method...
...
use Sort::Key qw(keysort);
...
cmpthese(-3, {
...
sk => '
use strict; use warnings;
my @sorted = keysort { substr($_, -(19+20), 19) } @::LogFileLi
+st;
',
});
that on my computer runs as...
Rate memoized st grt naive sk
memoized 8784/s -- -26% -51% -54% -58%
st 11894/s 35% -- -33% -38% -43%
grt 17794/s 103% 50% -- -7% -14%
naive 19207/s 119% 61% 8% -- -7%
sk 20714/s 136% 74% 16% 8% --
Note also that on my hardware,
naive is actually faster than
grt.
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.