Sorting higlighted items in array

Benchmark created on


Setup

const data = [...Array(1000).fill().map((el, i) => ({name: `item ${i}`, isHighlighted: i % 2 === 0 && i < 50, originalIndex: i}))]

Test runner

Ready to run.

Testing in
TestOps/sec
Sort
data.sort((a, b) => {
      if (a.isHighlighted == b.isHighlighted) return 0
      return a.isHighlighted ? -1 : 1
    })
ready
Concat
data.filter((el) => el.isHighlighted)
    .concat(
      data
        .filter((el) => !el.isHighlighted),
    )
ready

Revisions

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