Editing array copy This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Previous tests were also testing fn construction, not just pure array construction. This differs from http://jsperf.com/slice-vs-copy/ in that these are all function invocations, not just inline (which is basically always faster under 10 members). Pre-allocating the target array length, see http://jsperf.com/pre-allocationg-vs-literal. Note, the length of the array matters greatly, see http://jsperf.com/slice-vs-copy/ in the revisions/notes. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var arr = [1, 2, 3, 4, 5]; function forinclone(arr) { var key, arr_clone = []; for (key in arr) { arr_clone[key] = arr[key]; } return arr_clone; } function forclone(arr) { var i, len = arr.length, arr_clone = []; for (i = 0; i < len; i += 1) { arr_clone[i] = arr[i]; } return arr_clone; } function revforclone(arr) { var i, len = arr.length, arr_clone = []; for (i = len - 1; i >= 0; i -= 1) { arr_clone[i] = arr[i]; } return arr_clone; } function pushforclone(arr) { var i, len = arr.length, arr_clone = []; for (i = 0; i < len; i += 1) { arr_clone.push(arr[i]); } return arr_clone; } function whileclone(arr) { var len = arr.length, arr_clone = []; while (len--) { arr_clone[len] = arr[len]; } return arr_clone; } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code arr_clone = forinclone(arr); Test 2 Title Async (check if this is an asynchronous test) Code arr_clone = arr.slice(); Test 3 Title Async (check if this is an asynchronous test) Code arr_clone = arr.concat(); Test 4 Title Async (check if this is an asynchronous test) Code arr_clone = forclone(arr); Test 5 Title Async (check if this is an asynchronous test) Code arr_clone = pushforclone(arr); Test 6 Title Async (check if this is an asynchronous test) Code arr_clone = whileclone(arr); Test 7 Title Async (check if this is an asynchronous test) Code arr_clone = []; arr_clone.push.apply(arr_clone, arr); Test 8 Title Async (check if this is an asynchronous test) Code arr_clone = Array.prototype.slice.call(arr); Test 9 Title Async (check if this is an asynchronous test) Code arr_clone = revforclone(arr); Test 10 Title Async (check if this is an asynchronous test) Code arr_clone = []; Array.prototype.push.apply(arr_clone, arr);