scope variable visiting

JavaScript performance comparison

Revision 4 of this test case created by adventure

Preparation code

<script>
var i;

var accessGlobalVar = function () {
    for (i=0; i<1000000; i++) {}
}

var accessUpperScopeVar = (function () {
    var i;
    return function () {
        for (i=0; i<1000000; i++) {}
    };
})();

var accessUpperUpperScopeVar = (function () {
    var i;
    return (function () {
        return function () {
            for (i=0; i<1000000; i++) {}
        };
    })();
})();

var accessLocalVar = function () {
    var i;
    for (i=0; i<1000000; i++) {}
};

</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
directly access global var
for (i=0; i<1000000; i++) {}
pending…
access global var inside func
accessGlobalVar();
pending…
access upper scope var
accessUpperScopeVar();
pending…
access local var
accessLocalVar();
pending…
access more upper scope var
accessUpperUpperScopeVar();
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.

0 Comments