outer vs inner references

Benchmark created on


Preparation HTML

<script>
  var obj = {
      x : 10,
      y : 20,
      z : 30,
      w : window
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
outer reference
(function(){
    for(var i=0; i<1000; i++){
        obj.x + obj.y + obj.z + obj.w.alert + obj.w.document.getElementByID;
    }
})();
ready
inner reference
(function(){
    var x=obj.x, y=obj.y, z=obj.z, a=obj.w.alert, g=obj.w.document.getElementById;

    for(var i=0; i<1000; i++){
        x + y + z + a + g;
    }
})();
 
ready

Revisions

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