negative modulo (v15)

Revision 15 of this benchmark created by pusha on


Preparation HTML

<script>
var n = 5;

function f1(x) {
  return (x % n + n) % n;
}

function f2(x) {
  return x < 0 ? x % n + n : x % n;
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
no-if
var sum = 0;
for (var i = -1000, imax = 1000; i <= imax; ++i) {
  sum += f1(i);
}
ready
if
var sum = 0;
for (var i = -1000, imax = 1000; i <= imax; ++i) {
  sum += f2(i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.