Branch Prediction

JavaScript performance comparison

Test case created by Mike Frey and last updated

Info

Branch prediction comparison

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i = -1;
};
</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
if-else
var result;
var n = ++i;
if(n % 2) {
  result = "odd";
} else {
  result = "even";
}
pending…
ternary
var n = ++i;
var result = (n % 2) ? "odd" : "even";
pending…
alt
var n = ++i;
(n % 2) ? "odd" : (result = "even");
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