Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Firefox 137
Windows
Desktop
19 days ago
Test name Executions per second
[...array].sort 863.9 Ops/sec
array.toSorted 892.2 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)