Skip to content

Instantly share code, notes, and snippets.

@bdw
Last active August 19, 2018 08:12
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 bdw/42819001c1a08300bca54f818acf99b6 to your computer and use it in GitHub Desktop.
Save bdw/42819001c1a08300bca54f818acf99b6 to your computer and use it in GitHub Desktop.
minor benchmarks
#include <stdio.h>
/* this takes, excluding compilation, 0.23s on my machine.
* MoarVM is within a factor of three of that */
int main(int argc, char **argv) {
double x = 0;
int i;
for (i = 1; i < 50000000; i++)
x += 1.0/i;
printf("%f", x);
}
# this one is in nqp
# It takes 0.636s !!!!!
# a similar version in perl6, with native values, takes 1m43s
# a similar version in perl6, without boxing, takes 33s
my num $x := 0e0;
my int $i := 1;
while ($i < 50_000_000) {
$x := $x + 1e0/$i;
$i := $i + 1;
}
nqp::say("$x");
# this runs on either version of perl
# perl5 = 2.6s
# perl6 = 2m17s :-(
my $x = 0;
$x += 1/$_ for 1..50_000_000;
print "$x\n";
# this is optimized for perl6, using numerics
# perl6 = 31s
my $x = 0e0;
$x += 1e0/$_.Num for 1..50_000_000;
say $x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment