Array.toSort vs spread.sort

Benchmark created on


Setup

const arr = new Array(100000).map(() => Math.random())

function toSorted() {
	return arr.toSorted((a, b) => a - b)
}

function spreadSort() {
	return [...arr].sort((a, b) => a - b)
}

function mutatedSort() {
	return arr.sort((a, b) => a - b)
}

Test runner

Ready to run.

Testing in
TestOps/sec
toSorted
toSorted()
ready
spreadSort
spreadSort()
ready
mutatedSort
mutatedSort()
ready

Revisions

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