Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A hopelessly optimal case for the JIT compiler
#!/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