this vs var
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
this |
|
pending… |
var |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments