1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env perl6 use v6; my $n = 20; my $result; for ^$n { $result += $_ ** $_ } for ^10000 { my @p; my $sum = 0; for ^$n -> $i { push @p, Promise.start( { $sum += $i ** $i } ); } await @p; say $sum; die $_ if $sum != $result; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env perl6 use v6; my $n = 20; my $result; for ^$n { $result += $_ ** $_ } for ^10000 { my @p; my %hash; for ^$n -> $i { push @p, Promise.start( { %hash{$i} = $i ** $i } ); } await @p; my $sum = [+] %hash.values; say $sum ~ " $_"; die $_ if $sum != $result; }
1 2 3 4
#!/usr/bin/env perl6 use v6; my $files = dir( $*HOME ).race( batch => 10 );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/env perl6 use v6; my $n = 50; my $runs = 10000; my $result; for ^$n { $result += $_ ** $_ } for ^$runs { my @p; my $sum; my $lock = Lock.new; for ^$n -> $i { #push @p, Promise.start( { $lock.protect( { $sum += $i ** $i } ) } ); push @p, Promise.start( { my $t = $i ** $i; $lock.protect( { $sum += $t } ); } ); } await @p; say "$sum $_"; die $_ if $sum != $result; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/env perl6 use v6; my $n = 25_000; my $runs = 1; my $result; for ^$n { $result += $_ ** $_ } say $result; for ^$runs { my $sum = [+] await map { start { $_ ** $_ } }, ^$n; say "$sum $_"; die $_ if $sum != $result; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/env perl6 use v6; use Benchmark; my $n = 25_000; my $runs = 1; my $result; my @stats = timethis( $runs, sub { for ^$n { $result += $_ ** $_ } # ein Kern } ); say @stats; # 1441620270 1441620539 269 269 @stats = timethis( $runs, sub { my $sum = [+] await map { start { $_ ** $_ } }, ^$n; # benutzt alle 4 Kerne die "Error" if $sum != $result; } ); say @stats; # 1441620539 1441620618 79 79