Skip to content

Instantly share code, notes, and snippets.

@bdw
Created June 10, 2018 16:14
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/b3f265c0829f98c3087d5b93d4d064af to your computer and use it in GitHub Desktop.
Save bdw/b3f265c0829f98c3087d5b93d4d064af to your computer and use it in GitHub Desktop.
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