Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0
Firefox 134
Linux
Desktop
3 months ago
Test name Executions per second
[...array].sort 758.4 Ops/sec
array.toSorted 825.6 Ops/sec
Script Preparation code:
AخA
 
var array = Array.from({ length: 10_000 }).map((_) => Math.random());
var compareFn = (a, b) => a - b
Tests:
  • [...array].sort

     
    const result = [...array].sort(compareFn);
  • array.toSorted

     
    const result = array.toSorted(compareFn)