Closest-pair problem: Difference between revisions
m
→{{header|Raku}}: concurrency speeds things up considerably
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: eliminate a pair of temporary variables, add output) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: concurrency speeds things up considerably) |
||
Line 4,058:
{{trans|Perl 5}}
Using concurrency, the 'simple' routine beats the (supposedly) more efficient one for all but the smallest sets of input.
<lang perl6>sub MAIN ($N = 5000) {
my @points = (^$N).map: { [rand × 20 - 10, rand × 20 - 10] }
my @candidates =
say 'simple ' ~ (@candidates.sort: *.[2]).head(1).gist;
@candidates = @points.sort(*.[0]).rotor( 10 => -2, :partial).race.map: { closest-pair(@$_) }
say 'real ' ~ (@candidates.sort: *.[2]).head(1).gist;
}
Line 4,107 ⟶ 4,109:
}</lang>
{{out}}
<pre>simple (([-1.1560800527301716 -9.214015073077793] [-1.1570263876019649 -9.213340680530798] 0.0011620477602117762))
real (([-1.1570263876019649 -9.213340680530798] [-1.1560800527301716 -9.214015073077793] 0.0011620477602117762))</pre>
=={{header|REXX}}==
|