this vs var

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = {
      x: [1, 2, 3, 4, 5, 6],
      kittyThis: function() {
        var sum = 0;
        for (var i = 0, l = this.x.length; i < l; i++) sum += this.x[i];
        return sum;
      },
      kittyVar: function() {
        var sum = 0, x = this.x;
        for (var i = 0, l = x.length; i < l; i++) sum += x[i];
        return sum;
      }
    };
};
</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
a.kittyThis();
pending…
var
a.kittyVar();
pending…

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

Compare results of other browsers

0 comments

Add a comment