Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
imported>Rcmlz |
imported>Rcmlz |
||
Line 8,247: | Line 8,247: | ||
multi quicksort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted } |
multi quicksort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted } |
||
multi quicksort-parallel(@unsorted) { |
multi quicksort-parallel(@unsorted) { |
||
⚫ | |||
my $pivot = @unsorted.pick; |
my $pivot = @unsorted.pick; |
||
⚫ | |||
my %partitions{Order} is default([]) = @unsorted.classify( * cmp $pivot ); |
my %partitions{Order} is default([]) = @unsorted.classify( * cmp $pivot ); |
||
# atomically decide if we sort the Less partition on a new |
# atomically decide if we sort the Less partition on a new thread |
||
my $less = ⚛$worker > 0 && |
my $less = ⚛$worker > 0 && |
||
%partitions{Less}.elems > $BATCH-SIZE |
%partitions{Less}.elems > $BATCH-SIZE |
||
?? |
?? ( |
||
$worker⚛--; |
|||
start { |
|||
LEAVE $worker⚛++; |
|||
} |
samewith(%partitions{Less}) |
||
} |
|||
) |
|||
!! samewith(%partitions{Less}); |
!! samewith(%partitions{Less}); |
||
Line 8,333: | Line 8,334: | ||
<pre> |
<pre> |
||
Benchmarking by sorting 40960 strings of size 8 - using batches of 1024 strings and 4 workers. |
Benchmarking by sorting 40960 strings of size 8 - using batches of 1024 strings and 4 workers. |
||
[quicksort => |
[quicksort => 4.691771502 quicksort-parallel => 1.296705289] |
||
</pre> |
</pre> |
||