Var Scope Costs (v3)

Revision 3 of this benchmark created by CPD-Tech on


Preparation HTML

<script>
  var gObj = {
   count: 0,
   inc: function() {
    this.count++;
   },
   reset: function() {
    this.count = 0
   }
  }
  
  var cObj = (function() {
   var count = 0;
  
   function inc() {
    this.count++;
   };
  
   function reset() {
    this.count = 0
   }
   return {
    inc: inc,
    reset: reset
   };
  })();
  
  var loops = 100
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Global Object
gObj.reset();
for (var i = 0; i < loops; i++) {
 gObj.inc();
}
ready
Global Closure
cObj.reset();
for (var i = 0; i < loops; i++) {
 cObj.inc();
}
ready

Revisions

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