Boolean Lookup

JavaScript performance comparison

Test case created by Sebastian Werner

Info

For compression reasons it might sense to lay out boolean keywords into variables or translate their representation into something shorter. The test is for verifying how much it has negative side effect on the performance.

Preparation code

<script>
  var TRUE=true;
  var FALSE=false;
</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
Keywords
var data = [];
for(var i=0;i<10000;i++) {
  data.push(i%2 ? true : false);
}
pending…
Closure Vars
var data = [];
for(var i=0;i<10000;i++) {
  data.push(i%2 ? TRUE : FALSE);
}
pending…
Boolean Convertion
var data = [];
for(var i=0;i<10000;i++) {
  data.push(i%2 ? !0 : !1);
}
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