Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array slice vs while loop
(version: 1)
Comparing performance of:
While vs slice
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; const startIndex = 0;
Tests:
While
const endIndex = 14; let index = startIndex; const trimmedItems = []; while (index <= endIndex && index < items.length) { trimmedItems.push(items[index]); index++; }
slice
const trimmedItems = items.slice(startIndex, 15)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
While
slice
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
While
724422.9 Ops/sec
slice
9728782.0 Ops/sec
Related benchmarks:
Remove item from array by index
Add item to array3
reduce with slice
Last item in array Slice vs Length - 1
Last item in array Slice vs Length - 1 vs At -1
Last item in array Slice vs Length - 1 vs .at
Remove item from array by index (with Shift)
splice vs reduce- move item to the end
Last item in array Slice vs Length - 1 vs at(-1)
Comments
Confirm delete:
Do you really want to delete benchmark?