Convert truthy falsey to boolean true false

JavaScript performance comparison

Test case created by Chris

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var tnum = 1;
  var ttext = '1';
  var fnum = 0;
  var ftext = '';
  var NULL = null;
  var obj = {NULL:NULL, fnum:fnum,ftext:ftext,tnum:tnum, ttext:ttext};
  var x;

};
</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
bang bang
x = !!tnum;
x = !!fnum;
x = !!ttext;
x = !!ftext;
x = !!NULL;
x = !!undefined;
x = !!obj.tnum;
x = !!obj.fnum;
x = !!obj.ttext;
x = !!obj.ftext;
x = !!obj.NULL;
x = !!obj.undefined;
pending…
ternary
x = tnum ? true : false;
x = fnum ? true : false;
x = ttext ? true : false;
x = ftext ? true : false;
x = NULL ? true : false;
x = undefined ? true : false;
x = obj.tnum ? true : false;
x = obj.fnum ? true : false;
x = obj.ttext ? true : false;
x = obj.ftext ? true : false;
x = obj.NULL ? true : false;
x = obj.undefined ? true : false;
pending…

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

0 Comments