if vs cache

Benchmark created on


Preparation HTML

<script>
  function a() {}
  
  function b() {}
  cache = {};
  cache[a] = b;
  cache[b] = a;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
if
var odd = false;
for (var i = 0; i < 1000; i++) {
 if (odd) a();
 else b();
 odd = !odd;
}
ready
modulo
for (var i = 0; i < 1000; i++) {
 if ((i % 2) === 0) a();
 else b();
}
ready

Revisions

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