Closure Caching

JavaScript performance comparison

Test case created by Benny Bennet

Preparation code

<div id="test" style="width: 1000px"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var noClosure = function() {
      var a = document.getElementById('test').offsetWidth;
      var b = document.getElementById('test').offsetWidth;
      var c = document.getElementById('test').offsetWidth;
      return a + b + c;
  }
          
  var closure = (function() {
    var a = document.getElementById('test').offsetWidth;
    var b = document.getElementById('test').offsetWidth;
    var c = document.getElementById('test').offsetWidth;
  
    return function() {
      return a + b + c;
    }
  })();

};
</script>

Preparation code output

<div id="test" style="width: 1000px"></div>

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
No Closure Caching
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
console.log(noClosure());
pending…
Closure Caching
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
console.log(closure());
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