closures

JavaScript performance comparison

Test case created by roy

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var someVar = {
    someProp: {
      someOtherProp: 'someValue'
    }
  };
  
  var fn = function(val) {};

};
</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
accessing the global values
(function() {
  var someValue = someVar.someProp.someOtherProp;
  (function() {
    var someValueWillBeUsed = someValue;
    (function() {
      var someValueWillBeUsed = someValue;
      for (var i = 0; i < 10000; i++) {
        fn(someValueWillBeUsed);
      }
    }());
  }());
})();
pending…
passing the global variable in outer closure
(function(someValue) {
  (function() {
    var someValueWillBeUsed = someValue;
    (function() {
      var someValueWillBeUsed = someValue;
      for (var i = 0; i < 10000; i++) {
        fn(someValueWillBeUsed);
      }
    }());
  }());
})(someVar.someProp.someOtherProp);
pending…
passing the global variable internally
(function(someValue, f2) {
  var someValueWillBeUsed = someValue;
  (function(sv, f3) {
    var someValueWillBeUsed = someValue;
    for (var i = 0; i < 10000; i++) {
      f3(someValueWillBeUsed);
    }
  }(someValue, f2));
}(someVar.someProp.someOtherProp, fn));
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.

0 Comments