branch-prediction

JavaScript performance comparison

Test case created by and last updated

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var i = 0;
  
  function method1() {
    var result;
    var n = ++i;
    if(n % 2) {
      result = "odd";
    } else {
      result = "even";
    }
    return result;
  }
  
  function method2() {
    var n = ++i;
    var result = (n % 2) ? "odd" : "even";
    return result;
  }
  
  function method3() {
    var n = ++i;
    var result;
    (n % 2) ? (result = "odd") : (result = "even");
    return result;
  }

};
</script>

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
method 3
var r = method3();
pending…
method 2
var r = method2();
pending…
method 1
var r = method1();
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