Skip to content

Commit e600ff5

Browse files
author
Geoffrey Broadwell
committed
Add a rand microbenchmark
This is the fourth benchmark inspired by rc-forest-fire slowness, this time focusing on the performance of random floating point generation in the [0, 1) range.
1 parent b26da01 commit e600ff5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

microbenchmarks.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,12 @@
345345
perl6 => 'my $r = FatRat.new(0, 1); for 1 .. SCALE { $r += 1 / $_ }; say $r.perl',
346346
nqp => undef,
347347
},
348+
{
349+
name => 'rand',
350+
tags => [qw( for random forest-fire )],
351+
scale => 1 << 20,
352+
perl5 => 'my $total = 0; for (1 .. SCALE) { $total += rand }; say $total',
353+
perl6 => 'my $total = 0; for ^SCALE { $total += rand }; say $total',
354+
nqp => 'my $total := 0; my $i := 0; while $i++ < SCALE { $total := $total + nqp::rand_n(1) }; say($total)',
355+
},
348356
]

0 commit comments

Comments
 (0)