GRT or ST are not the fastest ways to sort in perl anymore:

Bold claim, but in my tests a simple sort wins from 10 to 1000+ data items, with a GRT taking over from 10,000 upto 1 million data items:

P:\test>466286 -N=10 Rate S::M GRT sort S::M 15958/s -- -22% -60% GRT 20443/s 28% -- -49% sort 39790/s 149% 95% -- P:\test>466286 -N=100 Rate S::M GRT sort S::M 1814/s -- -17% -40% GRT 2173/s 20% -- -28% sort 3024/s 67% 39% -- P:\test>466286 -N=1000 Rate S::M GRT sort S::M 157/s -- -5% -21% GRT 166/s 6% -- -17% sort 200/s 27% 20% -- P:\test>466286 -N=10000 Rate S::M sort GRT S::M 13.2/s -- -2% -3% sort 13.5/s 2% -- -0% GRT 13.6/s 3% 0% -- P:\test>466286 -N=100000 Rate sort S::M GRT sort 0.938/s -- -7% -11% S::M 1.01/s 7% -- -4% GRT 1.05/s 12% 4% -- P:\test>466286 -N=1000000 (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) s/iter sort S::M GRT sort 13.8 -- -8% -22% S::M 12.7 9% -- -16% GRT 10.7 29% 19% --

Benchmark

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; use Sort::Key::Maker sort_num_str => sub { /^(\d+)(.*)/ }, qw(num str); sub log10{ log( $_[ 0 ]) / log( 10 ) } our $N ||= 1000; our $CHECK ||= 0; our $ITERS = $CHECK ? 1 : -int( log10 $N ); our @data = map{ int( rand 1000 ) . ('A'..'Z')[ rand 26 ] } 1 .. $N; my %tests = ( sort => q[ my @sorted = sort{ $^W=0; $a<=>$b or $a cmp $b } @data; print "s:@sorted" if $CHECK; ], 'S::M' => q[ my @sorted = sort_num_str @data; print "S::M:@sorted" if $CHECK; ], GRT => q[ my @sorted = map { substr $_, 4 } sort map { $^W=0; pack 'NA*', 0+$_, $_ } @data; print "GRT:@sorted" if $CHECK; ], ); cmpthese $ITERS, \%tests;

Also, I got make test failures when building?

C:\Perl\packages\Sort-Key-0.10>nmake test Microsoft (R) Program Maintenance Utility Version 7.00.9466 Copyright (C) Microsoft Corporation. All rights reserved. C:\perl5.8.6\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test +_harness(0, 'blib\lib', 'blib\arch')" t\floats.t t\ints.t t\multi.t t +\strings.t t\floats.....ok t\ints.......ok 3/5 t\ints.......NOK 4# Failed test (t\ints.t at line 17) # Structures begin differing at: # $got->[0] = '9.1766357421875' # $expected->[0] = '9.2138671875' t\ints.......ok 5/5# Looks like you failed 1 test of 5. t\ints.......dubious Test returned status 1 (wstat 256, 0x100) DIED. FAILED test 4 Failed 1/5 tests, 80.00% okay t\multi......ok t\strings....ok Failed Test Stat Wstat Total Fail Failed List of Failed ---------------------------------------------------------------------- +--------- t\ints.t 1 256 5 1 20.00% 4 Failed 1/4 test scripts, 75.00% okay. 1/21 subtests failed, 95.24% oka +y. NMAKE : fatal error U1077: 'C:\perl5.8.6\bin\perl.exe' : return code ' +0xff' Stop.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^3: Sorting Alphanumeric Arrays by BrowserUk
in thread Sorting Alphanumeric Arrays by slloyd

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.