Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
`Array.slice(0, N)` vs `Array.length = N`
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Browser:
Firefox 124
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
`Array.length = N`
57.1M/s
`Array.slice(0, N)`
24.9M/s
`Object.assign([], arr)` with `Array.length = N`
656K/s
View exact numbers
Test name
Executions per second
✓
`Array.length = N`
57,142,856 Ops/sec
`Array.slice(0, N)`
24,869,852 Ops/sec
`Object.assign([], arr)` with `Array.length = N`
656,380 Ops/sec
Script Preparation code:
var arr = Array.from(Array(100).keys());
Tests:
`Array.slice(0, N)`
arr.slice(0, 20);
`Array.length = N`
arr.length = 20;
`Object.assign([], arr)` with `Array.length = N`
var newArr = Object.assign([], arr); newArr.length = 20;