Skip to content

Instantly share code, notes, and snippets.

@timo
Created April 15, 2017 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/a3a405f977840e8336f50234715e9cd4 to your computer and use it in GitHub Desktop.
Save timo/a3a405f977840e8336f50234715e9cd4 to your computer and use it in GitHub Desktop.
program from RT #129779 changed to run with n from 2 through 16
use v6;
my $r = 2_000_000;
say "Counting to $r";
my ($start, $setup, $stop);
$start = now;
{
my ($i, $j);
$j = $r;
loop ($i = 0; $i < $j; $i++) { }
}
$stop = now;
say "Non-promise iteration: {$stop - $start}";
my @promises;
$start = now;
@promises.push(start {
my ($i, $j);
$j = $r;
loop ($i = 0; $i < $j; $i++) { }
});
$setup = now;
await Promise.allof(@promises);
$stop = now;
say "One iteration: {$stop - $start} (setup: {$setup - $start})";
@promises = ();
for 2..16 -> $iters {
$start = now;
for (1..$iters) {
@promises.push(start {
my ($i, $j);
$j = $r;
loop ($i = 0; $i < $j; $i++) { }
});
}
$setup = now;
await Promise.allof(@promises);
$stop = now;
say "$iters iterations: {$stop - $start} (setup: {$setup - $start})";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment