Array.push(x) vs Array[array.length]=x

Benchmark created by geckotang on


Preparation HTML

<script>
  var a = [];
  var x = 0;
  var limit = 500000;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test1
for (x = 0; x < limit; x++) {
 a.push(x);
}
ready
test2
for (x = 0; x < limit; x++) {
 a[x] = x;
}
ready

Revisions

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

  • Revision 1: published by geckotang on