!! vs. normal

JavaScript performance comparison

Revision 3 of this test case created by Marshall Cline

Info

Fixed bug in v2 (!b) vs. (!!b), and reversed the sense so we are testing the speed of boolean-checking, not the speed of console.log().

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var logStuff = '';  // not a boolean, but a truthy/falsey value
};
</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 (!!logStuff) {
  console.log('what')
}
pending…
normal
if (logStuff) {
  console.log('what')
}
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