Skip to content

Commit 6547ae8

Browse files
author
Geoffrey Broadwell
committed
Add rc-9-billion-names minibenchmark
1 parent 8b08ec7 commit 6547ae8

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

minibenchmarks.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@
4747
perl6 => [qw( BENCH/perl6/rc-dragon-curve SCALE )],
4848
nqp => [qw( BENCH/nqp/rc-dragon-curve SCALE )],
4949
},
50+
{
51+
name => 'rc-9-billion-names',
52+
skip => [qw( )],
53+
scale => 1 << 7,
54+
perl5 => [qw( BENCH/perl5/rc-9-billion-names SCALE )],
55+
perl6 => [qw( BENCH/perl6/rc-9-billion-names SCALE )],
56+
nqp => [qw( BENCH/nqp/rc-9-billion-names SCALE )],
57+
},
5058
]

nqp/rc-9-billion-names

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
my @todo;
2+
my @sums;
3+
@todo.push([1]);
4+
@sums.push(0);
5+
sub nextrow($n) {
6+
my $l := +@todo;
7+
while $l <= $n {
8+
@sums[$l] := 0;
9+
# print($l, "\r") if $l < $n;
10+
my $r := [];
11+
my $x := $l - 1;
12+
while $x >= 0 {
13+
my @x := @todo[$x];
14+
if @x {
15+
$r.push: @sums[$x] := @sums[$x] + @x.shift;
16+
}
17+
else {
18+
$r.push: @sums[$x];
19+
}
20+
$x--;
21+
}
22+
@todo.push($r);
23+
$l++;
24+
}
25+
@todo[$n];
26+
}
27+
28+
sub MAIN(*@ARGS) {
29+
my $n := @ARGS[1];
30+
my $row := nextrow($n);
31+
my $sum := 0;
32+
$sum := $sum + $_ for $row;
33+
say($n, "\t", $sum);
34+
}

perl5/rc-9-billion-names

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use 5.010;
2+
3+
# Where perl6 uses arbitrary precision integers everywhere
4+
# that you don't tell it not to do so, perl5 will only use
5+
# them where you *do* tell it do so.
6+
use Math::BigInt;
7+
use constant zero => Math::BigInt->bzero;
8+
use constant one => Math::BigInt->bone;
9+
10+
my @todo = [one];
11+
my @sums = (zero);
12+
sub nextrow {
13+
my $n = shift;
14+
for my $l (@todo .. $n) {
15+
$sums[$l] = zero;
16+
# print "$l\r" if $l < $n;
17+
my @r;
18+
for my $x (reverse 0 .. $l-1) {
19+
my $todo = $todo[$x];
20+
$sums[$x] += shift @$todo if @$todo;
21+
push @r, $sums[$x];
22+
}
23+
push @todo, \@r;
24+
}
25+
@{ $todo[$n] };
26+
}
27+
28+
my $n = $ARGV[0];
29+
my $i = 0;
30+
$i += $_ for nextrow($n);
31+
say $n, "\t", $i;

perl6/rc-9-billion-names

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
my @todo = [1];
2+
my @sums = 0;
3+
sub nextrow($n) {
4+
for +@todo .. $n -> $l {
5+
@sums[$l] = 0;
6+
# print $l,"\r" if $l < $n;
7+
my $r = [];
8+
for reverse ^$l -> $x {
9+
my @x := @todo[$x];
10+
if @x {
11+
$r.push: @sums[$x] += @x.shift;
12+
}
13+
else {
14+
$r.push: @sums[$x];
15+
}
16+
}
17+
@todo.push($r);
18+
}
19+
@todo[$n];
20+
}
21+
22+
my $n = @*ARGS[0];
23+
say $n, "\t", [+] nextrow($n)[];

0 commit comments

Comments
 (0)