array access vs objectt access

JavaScript performance comparison

Test case created by cacajean and last updated

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
        //Base variable creation testing
        var read;
       
        var zero = 0;
        var blankObj = {};
        var blankArr = [];
       
        //Population limit for pre generated content
        var populateLimit = 6;
        var populateMid = populateLimit / 2;
        var populateNext = populateLimit + 1;
       
        var count = 0;
        var countMid = populateMid;
        var countNext = populateNext;
       
        var objPopLimit = 'p' + populateLimit;
        var objPopMid = 'p' + populateMid;
        var objPopNext = 'p' + populateNext;
        var objPopZero = 'p' + zero;
       
        //Premade content testing
        var testObj = {};
        for (var a = 0; a <= populateLimit; a++) {
          testObj['p' + a] = ('p' + a);
        }
        var testArr = [];
        for (var a = 0; a <= populateLimit; a++) {
          testArr[a] = ('p' + a);
        }
};
</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 access
var d = testObj.p3;
pending…
array access
var e = testArr.valueOf(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