Global - Case 3
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var obj = {};
var v = obj.v = self.v = 0;
function test1() {
self.v += 1;
}
function test2() {
obj.v += 1;
}
function test3() {
v += 1;
}
function bench(func) {
for (var i = 0; i < 50000; i++) func();
}
};
Benchmark.prototype.teardown = function() {
v = obj.v = self.v = 0;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
self.v+=1 |
|
pending… |
obj.v += 1 |
|
pending… |
v += 1 (Closure) |
|
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 by Cong Liu
- Revision 2: published by Cong Liu
- Revision 3: published
0 comments