Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1

by Eily (Monsignor)
on Feb 05, 2019 at 14:34 UTC ( #1229411=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      eily => sub {
        my @list = -50..50;
        @list = sort { ~$b <=> ~$a } @list;
        Compare(\@list,[0..50,-50..-1]) or die "@list" if DO_CHECK;
      }
    
  2. or download this
                 Rate grepfirst sortfirst      eily
    grepfirst 59577/s        --      -14%      -32%
    sortfirst 69292/s       16%        --      -21%
    eily      87583/s       47%       26%        --
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229411]
help
Chatterbox?
and the web crawler heard nothing...

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







    Results (82 votes). Check out past polls.

    Notices?