Perl fastest sorting algorithm -


i trying find fastest sorting algorithm in perl. searching cpan found algorithm::sorting module. tried simple code below find best sorting algorithm results vary every time change data list. module not support merge, heap, , quick3 sorts, these matter also.

#!/usr/bin/perl  use algorithm::sorting; use benchmark qw(:all);  @list = (int rand(1000_000)) x 10000;  @sorts = qw(bubblesort shakersort selectionsort insertionsort shellsort quicksort); #algorithm: bubble heap insertion merge quick quick3 selection shell  #my @test = @list; #bubblesort(@test); #print "@test\n";  cmpthese (10, {     bubblesort    => sub { bubblesort([@list]) },     shakersort    => sub { shakersort([@list]) },     selectionsort => sub { selectionsort([@list]) },     insertionsort => sub { insertionsort([@list]) },     shellsort     => sub { shellsort([@list]) },     quicksort     => sub { quicksort([@list]) }, }); 

below benchmark results:

                     rate bubblesort selectionsort quicksort shellsort insertionsort shakersort bubblesort    7.09e-002/s         --          -30%      -99%     -100%         -100%      -100% selectionsort     0.102/s        43%            --      -99%     -100%         -100%      -100% quicksort          10.5/s     14707%        10247%        --      -54%          -79%       -80% shellsort          22.9/s     32157%        22440%      118%        --          -54%       -57% insertionsort      49.3/s     69339%        48422%      369%      115%            --        -8% shakersort         53.5/s     75281%        52573%      409%      134%            9%         --  output completed (4 min 1 sec consumed) 


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -