closure lookup

JavaScript performance comparison

Revision 5 of this test case created by Jason Miller

Preparation code

<script>
var a = (function() {
        var local = ['a', 'b'];
        return function(x) {
                return local[x];
        }
}());

var b = function(x) {
        var local = ['a', 'b'];
        return local[x];
};

var local = ['a', 'b'];
var c = function(x) {
        return local[x];
};

var d = (function() {
  "use strict";
        var local = ['a', 'b'];
        return function(x) {
                return local[x];
        }
}());

var obj = {
        local : ['a', 'b'],
        e : function(x) {
                return obj.local[x];
        }
};
var e = obj.e;
</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
anonymous closure
a(1);
a(0);
pending…
redefined array
b(1);
b(0);
pending…
Stored Array
c(1);
c(0);
pending…
Strict Closure
d(1);
d(0);
pending…
Property Lookup
e(1);
e(0);
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