Array push vs set index

Benchmark created by Jon Mumm on


Setup

var a = []

Test runner

Ready to run.

Testing in
TestOps/sec
Push
for (var i = 0; i < 1000; i++) {
  a.push(i);
}
ready
Set by index
for (var i = 0; i < 1000; i++) {
  a[i] = i;
}
ready
Set with index using length
for (var i = 0; i < 1000; i++) {
  a[a.length] = 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