Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Alas, mine is the slowest so far...

use warnings; use strict; use Benchmark 'cmpthese'; use constant DO_CHECK => 0; use if DO_CHECK, 'Data::Compare', qw/Compare/; my @GLOBAL_LIST = -5 .. 5; cmpthese(-2, { sortfirst => sub { my @list = @GLOBAL_LIST; @list = sort {$a<=>$b} @list; @list = ( (grep {$_>=0} @list), (grep {$_<0} @list) ); DO_CHECK and ( Compare(\@list,[0..5,-5..-1]) or die "@list"); }, grepfirst => sub { my @list = @GLOBAL_LIST; my @pos = grep {$_>=0} @list; my @neg = grep {$_<0} @list; @list = ( (sort {$a<=>$b} @pos), (sort {$a<=>$b} @neg) ); DO_CHECK and ( Compare(\@list,[0..5,-5..-1]) or die "@list"); }, pryrt => sub { my @list = @GLOBAL_LIST; sub sgn { $_[0]<0?-1:1 } @list = (sort {(sgn($b) <=> sgn($a)) || ($a <=> $b)} @list); DO_CHECK and ( Compare(\@list,[0..5,-5..-1]) or die "@list"); }, choroba => sub { my @in = @GLOBAL_LIST; my @sorted = sort { ((-1, 0, 1)[$a <=> 0] <=> (-1, 0, 1)[$b <=> 0]) || ($a <=> + $b) } @in; DO_CHECK and ( Compare(\@sorted,[0..5,-5..-1]) or die "@sorted +"); } }); __END__ Rate pryrt choroba grepfirst sortfirst pryrt 89602/s -- -26% -67% -74% choroba 120426/s 34% -- -56% -65% grepfirst 271358/s 203% 125% -- -20% sortfirst 340119/s 280% 182% 25% --

In reply to Re: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1 by pryrt
in thread Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1 by haukex

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2021-10-21 03:11 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (82 votes). Check out past polls.