conditional by value or boolean

JavaScript performance comparison

Test case created by Josh

Info

Speed difference between checking a 0/1 value or a true/false value.

Preparation code

<div>
  Alons y
</div>
<script>
Benchmark.prototype.setup = function() {
    $res = 0;
};
</script>

Preparation code output

Alons y

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Check for value
function checkVal() {
  if ($res == 0) {
    //code
  }
}
checkVal();
pending…
Check for boolean
function checkBool() {
  if (!$res) {
    //code
  }
}
checkBool();
pending…

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

Compare results of other browsers

0 comments

Add a comment