Last active
August 19, 2018 08:12
-
-
Save bdw/42819001c1a08300bca54f818acf99b6 to your computer and use it in GitHub Desktop.
minor benchmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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