copy-loop vs. Array.slice

Benchmark created by Lars Schultz on


Description

The performance difference between copying an array by hand and copying it by slicing it (completely). This is for short arrays.

Setup

var list = ['a','b','c'];

Test runner

Ready to run.

Testing in
TestOps/sec
Copy-Loop
var copy = new Array();
for ( var i=0;i<list.length; i++ ) copy.push(list[i]);
ready
Array-Slice
var copy = list.slice();
ready

Revisions

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