Skip to content

Instantly share code, notes, and snippets.

@hankache
Created April 4, 2016 08:01
Show Gist options
  • Save hankache/bbbe41812a1dceb6f6e478ff5228e383 to your computer and use it in GitHub Desktop.
Save hankache/bbbe41812a1dceb6f6e478ff5228e383 to your computer and use it in GitHub Desktop.
#No parallel
my @array1 = (0..49999);
my @array2 = (2..50001);
my @result1 = @array1.map( {is-prime($_ + 1)} );
my @result2 = @array2.map( {is-prime($_ - 1)} );
say @result1 == @result2;
say now - INIT now;
#parallel
my @array1 = (0..49999);
my @array2 = (2..50001);
my $promise1 = start @array1.map( {is-prime($_ + 1)} );
my $promise2 = start @array2.map( {is-prime($_ - 1)} );
my @result1 = await $promise1;
my @result2 = await $promise2;
say @result1 == @result2;
say now - INIT now;
@jonathanstowe
Copy link

my @array1 = (0..49999);
my @array2 = (2..50001);

my $promise1 = start {
                        say "starting one ";
                        my @a = @array1.map( {is-prime($_ + 1)} );
                        say "done one ";
                        @a;
                     };
my $promise2 = start {
                        say "starting two";
                        my @a = @array2.map( {is-prime($_ - 1)} );
                        say "done two";
                        @a;
                     };


my @result1 = await $promise1;
my @result2 = await $promise2;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment