array.shift() vs Object key update in array of Objects

Benchmark created by Martin Ambrus on


Setup

let arr = [];
  for (var i = 0; i < 10000; i++) {
    arr[i] = {
      'key1' : 'value1',
      'key2' : 'value2',
      'key3' : 'value3'
    };
  }

Test runner

Ready to run.

Testing in
TestOps/sec
array.shift
while (arr.length) {
  arr.shift();
}
ready
Object - set key's value
while (1) {
for (var i in arr) {
  if (!arr[i].hasOwnProperty('done')) {
    arr[i]['done'] = 1;
    continue;
  }
}
break;
}
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