Last active
September 4, 2015 20:47
-
-
Save MattOates/125009c88f6ee9f5f101 to your computer and use it in GitHub Desktop.
Do some parallel prime finding in the most naive way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
use Stats; | |
sub bench($name, &code) { | |
my ($start,$end); | |
my $max = 1000; | |
my @times; | |
for 1..100 { | |
$start = now; | |
code($max); | |
$end = now; | |
@times.push($end-$start); | |
} | |
my $sd = sd @times; | |
my $mu = mean @times; | |
say "$name: ran in $mu seconds (σ = $sd seconds)"; | |
} | |
bench 'primes-parallel', { | |
my @primes = (2 .. $^max).race(batch => $^max / 2, degree => 2).grep({ | |
(2 .. $^n - 1).race(batch => $^n / 2, degree => 2).grep($^n %% *).elems == 0; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ perl6 parallel-primes.p6
No exception handler located for catch
at src/gen/m-CORE.setting:677 (/Users/matt/.rakudobrew/moar-glr/install/share/perl6/runtime/CORE.setting.moarvm:THROW-NIL:6)
from src/gen/m-CORE.setting:732 (/Users/matt/.rakudobrew/moar-glr/install/share/perl6/runtime/CORE.setting.moarvm:next:12)
$ perl6 parallel-primes.p6
moar(2277,0x1138fc000) malloc: *** error for object 0x7fc0a8817688: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
/Users/matt/.rakudobrew/bin/perl6: line 2: 2277 Abort trap: 6 PATH=/Users/matt/.rakudobrew/bin/../moar-glr/install/bin:$PATH perl6 "$@"