Array push vs set index (v5)

Revision 5 of this benchmark created by bobbytables on


Setup

var a;
    var len;

Test runner

Ready to run.

Testing in
TestOps/sec
Push
a = [];
for (var i = 0; i < 1000; i++) {
  a.push(i);
}
ready
Set by index
a = [];
for (var i = 0; i < 1000; i++) {
  a[i] = i;
}
ready
Set with index using length
a = [];
for (var i = 0; i < 1000; i++) {
  a[a.length] = i;
}
ready
Set with index using local length
a = [];
len = 0;
for (var i = 0; i < 1000; i++) {
  a[len++] = i;
}
ready

Revisions

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

  • Revision 1: published by Jon Mumm on
  • Revision 3: published by daniel on
  • Revision 4: published by bobbytables on
  • Revision 5: published by bobbytables on
  • Revision 6: published on