Combining and sorting arrays: sorted vs unsorted (v2)

Revision 2 of this benchmark created on


Setup

function mergeAndSort(arr1, arr2){
  return arr1.concat(arr2).sort((a, b) => a - b)
}

Test runner

Ready to run.

Testing in
TestOps/sec
Combine & sort unsorted arrays
mergeAndSort(
  [
   75,58,82,61,81,54,78,83,67,72,99,69,95,80,51,
   86,89,62,65,87,91,60,71,59,96,77,88,79,84,57,
   68,74,50,63,97,85,90,94,92,53,64,98,66,70,55,
   93,56,76,52,73
  ],
  [
   41,49,34,18,32,2,1,12,42,46,15,29,47,19,27,
   25,23,39,36,48,11,7,16,13,6,37,38,43,33,0,
   22,35,9,14,44,31,8,26,21,17,24,5,30,20,40,
   10,45,28,3,4
  ]
)
ready
Combine & sort pre-sorted arrays
mergeAndSort(
  [
   50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,
   66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
   81,82,83,84,85,86,87,88,89,90,91,92,93,94,
   95,96,97,98,99
  ],
  [
   0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
   15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
   30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,
   45,46,47,48,49
  ]
)
ready
Combine & sort pre-sorted arrays (alternating)
mergeAndSort(
  [
   0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,
   30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,
   60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,
   90,92,94,96,98
  ],
  [
   1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,
   31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,
   61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,
   91,93,95,97,99
  ]
)
ready

Revisions

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