Created
June 10, 2018 16:14
-
-
Save bdw/b3f265c0829f98c3087d5b93d4d064af to your computer and use it in GitHub Desktop.
A hopelessly optimal case for the JIT compiler
This file contains 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
#!/usr/bin/env nqp | |
# From https://www.johnhawthorn.com/2018/02/playing-with-ruby-jit-mjit/ | |
sub calculate(int $a, int $b, int $n) { | |
my int $i := 0; | |
my int $c := 0; | |
while $i < $n { | |
$a := $a * 16807 % 2147483647; | |
$b := $b * 48271 % 2147483647; | |
if ($a +& 0xffff == $b +& 0xffff) { | |
$c := $c + 1; | |
} | |
$i := $i + 1; | |
} | |
return $c; | |
} | |
nqp::say(calculate(65, 8921, 40_000_000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment