Loop vs Slice copy (v47)

Revision 47 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
splice copy
var copy = data.slice(0);
ready
Loop fixed 2
var copy = new Array(data.length);
for (var j = 0, l = data.length; j < l; j++) {
  copy[j] = data[j];
}
ready
Loop fixed while
var len = data.length;
var copy = new Array(len);
while(len--) {
  copy[len] = data[len];
}
ready
Loop Copy
var copy = []
for (var j = 0; j < data.length; j++) {
  copy.push(data[j]);
}
ready
Loop Fixed
var copy = new Array(data.length);
for (var j = 0; j < data.length; j++) {
  copy[j] = data[j];
}
ready

Revisions

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