Var Scope Costs (v2)

Revision 2 of this benchmark created by CPD-Tech on


Preparation HTML

<script>
  var gVar = 0;
  var obj = {
   oVar: 0,
   test1: function() {
    gVar = 0;
    gVar++;
   },
   test2: function() {
    this.oVar = 0;
    this.oVar++;
   },
   test3: function() {
    var lVar = 0;
    lVar++;
   },
   test4: function() {
    window.gVar = 0;
    window.gVar++;
   }
  
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Global Scope
obj.test1();
ready
Object Scope
obj.test2();
ready
Local Scope
obj.test3();
ready
Global with Window Ref
obj.test4();
ready

Revisions

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