Run details:
Mozilla/5.0 (X11; CrOS x86_64 14695.114.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Chrome 102
Chrome OS 14695.114.0
Desktop
24 days ago
Test name Executions per second
Array.sort() 147144.2 Ops/sec
Array.toSorted() 0.0 Ops/sec
[...Array].sort() 65389.5 Ops/sec
Script Preparation code:
x
 
array = Array.from({
    length: 50
}, (x, i) => (Math.round(Math.random() * (i + .01) * 1000)))
sortNumeric = (a, b) => (Number(a) - Number(b));
Tests:
  • Array.sort()

     
    array.sort(sortNumeric);
  • Array.toSorted()

     
    array.toSorted(sortNumeric)
  • [...Array].sort()

     
    [...array].sort(sortNumeric);