Object Loops - String Index vs. Number Index

JavaScript performance comparison

Revision 4 of this test case created by Andrew


Which is better performance on large loops, objects with string indexes or number indexes?

Preparation code

Benchmark.prototype.setup = function() {
    var the_digital_object, the_stringy_object, i, len, result;
    the_digital_object = {};
    the_stringy_object = {};
    for (i = 0; i< 10000; i++) {
      the_digital_object[i] = "foobar";
      the_stringy_object["index" + i] = "foobar";

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Digital Indexes
for (i in the_digital_object) {
  result = the_digital_object[i];
Stringy Indexes
for (i in the_stringy_object) {
  result = the_stringy_object[i];

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment