this versus local variable

JavaScript performance comparison

Revision 5 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Item1() {
      this.option = {
        tolerance: {
          l: 4
        }
      };
    }
   
    Item1.prototype.f = function() {
      var option = this.option,
        tolerance;
   
      tolerance = option.tolerance.l;
   
      return tolerance + tolerance;
   
    }
   
    function Item2() {
      this.option = {
        tolerance: {
          l: 4
        }
      };
    }
   
    Item2.prototype.f = function() {
      var option = this.option,
        tolerance = option.tolerance,
        toleranceL;
   
      toleranceL = tolerance.l;
      return toleranceL + toleranceL;
    }
   
    var thisInstance = new Item1();
    var localInstance = new Item2();
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
This
for (var i = 0; i < 100000; i++) {
  thisInstance.f();
}
pending…
Local
for (var i = 0; i < 100000; i++) {
  localInstance.f();
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment