Global variables vs config object
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var test1 = 0,
test2 = 0,
test3 = 0,
test4 = 0,
test5 = 0;
var configObject = {
test1: 0,
test2: 0,
test3: 0,
test4: 0,
test5: 0
}
function configFunction () {
this.test1 = 0;
this.test2 = 0;
this.test3 = 0;
this.test4 = 0;
this.test5 = 0;
}
configFunction.prototype.increment = function () {
this.test1++;
this.test2++;
this.test3++;
this.test4++;
this.test5++;
}
inner = new configFunction();
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Global variables |
|
pending… |
Config object |
|
pending… |
Function from outside |
|
pending… |
Function with 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 by BogdanB
- Revision 2: published by BogdanB
- Revision 3: published by Trey Keown
0 comments