Objects vs Arrays value juggling speed

Benchmark created by Martin Ambrus on


Setup

var arr = [];
  var obj = {};
  var objLength = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Array push + shift
for (var i = 0; i <= 10000; i++) {
  arr.push({
    magic: 0,
    attributes: 0,
    key: 'abcdAAACX',
    value: '{"someValue1":"X55e8A6","someValue2":"25","someValue3":25,"someValue4":5299,"someValue5":89220}'
  });
}

while (arr.length) {
  console.log('removing: ' + arr.shift());
}
ready
Object - set + delete
for (var i = 0; i <= 10000; i++) {
  obj[i] = {
    magic: 0,
    attributes: 0,
    key: 'abcdAAACX',
    value: '{"someValue1":"X55e8A6","someValue2":"25","someValue3":25,"someValue4":5299,"someValue5":89220}'
  };
  objLength++;
}

while (objLength) {
  console.log('removing: ' + obj[objLength - 1]);
  delete obj[objLength - 1];
  objLength--;
}
ready

Revisions

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

  • Revision 1: published by Martin Ambrus on