branch-prediction

JavaScript performance comparison

Test case created 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 unknown unknown
Test Ops/sec
method 1
var r = method1();
pending…
method 2
var r = method2();
pending…
method 3
var r = method3();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment