local var vs this.
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var F = function() {};
F.prototype.foo = 20;
F.prototype.local = function() {
var bar = this.foo;
for (var i = 0; i < 10000; i++) {
bar += i >> 8;
}
this.foo = bar;
}
F.prototype.scoped = function() {
for (var i = 0; i < 10000; i++) {
this.foo += i >> 8;
}
}
var inst = new F();
};
Benchmark.prototype.teardown = function() {
inst.foo = 20;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
local |
|
pending… |
this |
|
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:
- Revision 1: published
0 comments