Global variables vs config object

JavaScript performance comparison

Revision 3 of this test case created by Trey Keown

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.

Testing in unknown unknown
Test Ops/sec
Global variables
test1++;
test2++;
test3++;
test4++;
test5++;
pending…
Config object
configObject.test1++;
configObject.test2++;
configObject.test3++;
configObject.test4++;
configObject.test5++;
pending…
Function from outside
configFunction.test1++;
configFunction.test2++;
configFunction.test3++;
configFunction.test4++;
configFunction.test5++;
pending…
Function with this
inner.increment();
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:

0 comments

Add a comment