Loop vs Slice copy (v32)

Revision 32 of this benchmark created on


Setup

var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Test runner

Ready to run.

Testing in
TestOps/sec
loop copy
var copy = []
for (var j = 0; j < data.length; j++) {
  copy.push(data[j]);
}
ready
splice copy
var copy = data.slice(0);
ready
loop fixed size
var i = data.length,
  copy = new Array(i);
while (i--) {
  copy[i] = data[i];
}
ready

Revisions

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