Reversing array - slice() vs. concat()

Benchmark created on


Setup

// Generate an array of 1000 nodes sorted by depth ascending
const nodes = Array.from({ length: 1000 }, (_, i) => ({ id: i, depth: i }));

Test runner

Ready to run.

Testing in
TestOps/sec
slice()
const reversedNodesSlice = nodes.slice().reverse();
ready
concat()
const reversedNodesConcat = [].concat(nodes).reverse();
ready

Revisions

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