Skip to content

Instantly share code, notes, and snippets.

@Util
Created February 11, 2016 13:51
Show Gist options
  • Save Util/396706dac28c720379dc to your computer and use it in GitHub Desktop.
Save Util/396706dac28c720379dc to your computer and use it in GitHub Desktop.
Perl 6 benchmark for Atlanta.pm to play with on new massive multicore server
use v6;
# 2016-02-09 <bruce.gray@acm.org>
my $length = @*ARGS.shift;
say "Length = $length";
my @x = 1..$length;
my @y = @x.reverse;
sub zipped {
my @r = @x Z+ @y;
}
sub hypered {
my @r = @x »+« @y;
}
sub looped {
my @r;
for @x Z @y -> ($x, $y) {
push @r, $x + $y;
}
}
sub mapped {
my @r = (@x Z @y).map(-> ($x, $y) { $x + $y });
}
sub gathered {
my @r = gather for @x Z @y -> ($x, $y) {
take $x + $y;
};
}
use Bench;
my Bench $b .= new;
$b.cmpthese( 1000, {
:&zipped,
:&hypered,
:&looped,
:&gathered,
:&mapped,
});
This is from my MacBook Pro laptop, running Rakudo Star 2015.11, with lengths of 100 and 1000.
bg:~ $ perl6 hyper_benchmark.p6 100
Length = 100
Benchmark:
Timing 1000 iterations of gathered, hypered, looped, mapped, zipped...
gathered: 16.4358 wallclock secs @ 60.8427/s (n=1000)
hypered: 6.9882 wallclock secs @ 143.0991/s (n=1000)
looped: 17.2923 wallclock secs @ 57.8293/s (n=1000)
mapped: 19.5308 wallclock secs @ 51.2011/s (n=1000)
zipped: 13.5465 wallclock secs @ 73.8198/s (n=1000)
O----------O--------O--------O--------O--------O----------O---------O
| | Rate | mapped | zipped | looped | gathered | hypered |
O==========O========O========O========O========O==========O=========O
| mapped | 51.2/s | -- | -31% | -11% | -16% | -64% |
| zipped | 73.8/s | 44% | -- | 28% | 21% | -48% |
| looped | 57.8/s | 13% | -22% | -- | -5% | -60% |
| gathered | 60.8/s | 19% | -18% | 5% | -- | -57% |
| hypered | 143/s | 179% | 94% | 147% | 135% | -- |
---------------------------------------------------------------------
bg:~ $ perl6 hyper_benchmark.p6 1000
Length = 1000
Benchmark:
Timing 1000 iterations of gathered, hypered, looped, mapped, zipped...
gathered: 163.4539 wallclock secs @ 6.1179/s (n=1000)
hypered: 72.5322 wallclock secs @ 13.7870/s (n=1000)
looped: 183.3005 wallclock secs @ 5.4555/s (n=1000)
mapped: 210.7990 wallclock secs @ 4.7439/s (n=1000)
zipped: 153.3177 wallclock secs @ 6.5224/s (n=1000)
O----------O--------O--------O--------O--------O----------O---------O
| | Rate | mapped | zipped | looped | gathered | hypered |
O==========O========O========O========O========O==========O=========O
| mapped | 4.74/s | -- | -27% | -13% | -22% | -66% |
| zipped | 6.52/s | 37% | -- | 20% | 7% | -53% |
| looped | 5.46/s | 15% | -16% | -- | -11% | -60% |
| gathered | 6.12/s | 29% | -6% | 12% | -- | -56% |
| hypered | 13.8/s | 191% | 111% | 153% | 125% | -- |
---------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment