Module vs bitwise and

Benchmark created on


Description

For checking whether a number is even or not, both % and & operators can be used.

Preparation HTML

<script>
  var correct;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Modulo
for (var i = 0; i < 20; ++i) {
 if (i % 1) {
  correct = false;
 }
}
ready
Bitwise and
for (var i = 0; i < 20; ++i) {
 if (i & 1) {
  correct = false;
 }
}
ready

Revisions

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