a / b || 0 int

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div>
  a:
  <span id='a'>
    0
  </span>
  b:
  <span id='b'>
    0
  </span>
  c:
  <span id='c'>
    0
  </span>
</div>
      
<script>
Benchmark.prototype.setup = function() {
  counter = 0;
  aSpan = $('#a');
  bSpan = $('#b');
  cSpan = $('#c');
  
  function intOrUndef() {
    ret = counter++;
    if (ret % 25 == 0) {
      ret = undefined;
    }
    return ret;
  }
  
  
  function display(a, b, c) {
    aSpan.text(a);
    bSpan.text(b);
    cSpan.text(c);
  }

};
</script>

Preparation code output

<div> a: <span id='a'> 0 </span> b: <span id='b'> 0 </span> c: <span id='c'> 0 </span> </div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
1 - (a / b || 0)
a = 1;
b = intOrUndef();
c = 1 - (a / b || 0);
display(a, b, c);
pending…
b ? 1 - (a / b) : 1
a = 1;
b = intOrUndef();
c = b ? 1 - (a / b) : 1;
display(a, b, c);
pending…
1 - ((a / b) || 0)
a = 1;
b = intOrUndef();
c = 1 - ((a / b) || 0);
display(a, b, c);
pending…

Compare results of other browsers

Revisions

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

0 Comments

a: 0 b: 0 c: 0