Speed of Arr.length and Slice
Date tested:
2 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Test name
Executions per second
slice
20647936.0 Ops/sec
arr.length
15768275.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var arr = []; for (let i = 0; i < 1000000; i++) { arr.push(i); }
Tests:
slice
arr.slice(-1)
arr.length
arr[arr.length-1]
Open this result on MeasureThat.net