Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
JS Fastest Array Shallow Copy
Testing the results for the fastest approach of shallow copying an array in JavaScript (concat, slice, for loop, and while loop).
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
Array.slice
99.3M/s
For loop
17.8M/s
For loop with declared length
17.6M/s
While loop
16.8M/s
Array.concat
14.5M/s
View exact numbers
Test name
Executions per second
✓
Array.slice
99,317,656 Ops/sec
For loop
17,755,298 Ops/sec
For loop with declared length
17,594,042 Ops/sec
While loop
16,758,249 Ops/sec
Array.concat
14,492,913 Ops/sec
Tests:
Array.concat
var a = [ "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello" ]; var b = []; var other = a.concat(b);
Array.slice
var a = [ "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello" ]; var b = a.slice();
For loop
var a = [ "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello" ]; var b = []; for (let i = 0; i < a.length; ++i) { b.push(a[i]); }
For loop with declared length
var a = [ "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello" ]; var b = []; const length = a.length; for (let i = 0; i < length; ++i) { b.push(a[i]); }
While loop
var a = [ "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello" ]; var b = []; let i = a.length - 1; while (--i) { b.push(a[i]); }