Ways of accessing stuff

JavaScript performance comparison

Test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i;
    var obj = {};
   
    obj.a = 1;
    obj.b = 2;
    obj.c = 3;
    obj.d = 4;
   
    var arr = [];
    arr[0] = 1;
    arr[1] = 2;
    arr[3] = 3;
    arr[4] = 4;
   
};
</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
Object way
i = obj["a"];
i = obj["b"];
i = obj["c"];
i = obj["d"];
pending…
Object way 2
i = obj.a; 
i = obj.b;
i = obj.c;
i = obj.d;
pending…
Arr way
i = arr[0];
i = arr[1];
i = arr[2];
i = arr[3];
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment