new array vs splice vs reuse (v4)

Revision 4 of this benchmark created by Adam Pflug on


Description

Different method to replace the content of an array...

Preparation HTML

<script>
  var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
b = [];
for (var i = 0, len = a.length; i < len; i++) {
 if (i == 7) {
  b.push(88);
 }
 b.push(a[i]);
}
ready
Splice
a.splice(7, 0, 88);
ready
Shift
for (var i = a.length; i > 7; i--) {
 a[i] = a[i - 1];
}
a[7] = 88;
ready

Revisions

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