Delete in a loop vs change length

Benchmark created on


Setup

const itemCount = 500
let items = new Array(itemCount).fill('Hello World')
const toDelete = 300

Test runner

Ready to run.

Testing in
TestOps/sec
Loop
items = items.slice(0, itemCount - toDelete)
ready
Truncate Length
items.length = itemCount - toDelete
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.