Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 17:40 UTC ( [id://1229425]=note: print w/replies, xml ) Need Help??


in reply to Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1

I've got this one which runs faster than Discipulus' original version, but I can't get any of them to run faster than vr's on my computer:

GrepPos => sub{ my @list = @input; my $pos = grep { $_ >= 0 } @list; @list[$pos..$#list, 0..$pos-1] = sort {$a<=>$b} @list; Compare(\@list,\@output) or die "@list" if DO_CHECK; },
(Edit: it's a rewritten version of Discipulus2 so I just ++ed it :P)
(Edit2: wait... that's just sortfirst with a grep in scalar context... Haukupulus?)
(Edit3: it was called Discipulus3 which was a bad idea, renamed it GrepPos)
Rate Eily Discipulus Discipulus3 vr Eily 21060/s -- -55% -61% -65% Discipulus 47134/s 124% -- -13% -22% GrepPos 54377/s 158% 15% -- -10% vr 60414/s 187% 28% 11% --

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found