Sorting algorithms/Quicksort: Difference between revisions

imported>Rcmlz
imported>Rcmlz
Line 8,247:
multi quicksort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted }
multi quicksort-parallel(@unsorted) {
# separate unsorted input into Order Less, Same and More compared to a random $pivot
my $pivot = @unsorted.pick;
 
# separate unsorted input into Order Less, Same and More compared to $pivot
my %partitions{Order} is default([]) = @unsorted.classify( * cmp $pivot );
 
# atomically decide if we sort the Less partition on a new worker thread
my $less = ⚛$worker > 0 &&
%partitions{Less}.elems > $BATCH-SIZE
?? start( {
ENTER $worker⚛--;
start LEAVE $worker⚛++; {
samewith(%partitions{Less})LEAVE $worker⚛++;
samewith(%partitions{Less})
}
)
!! samewith(%partitions{Less});
 
Line 8,333 ⟶ 8,334:
<pre>
Benchmarking by sorting 40960 strings of size 8 - using batches of 1024 strings and 4 workers.
[quicksort => 54.271144286691771502 quicksort-parallel => 21.645456851296705289]
</pre>
 
Anonymous user