Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Firefox 134
Windows
Desktop
3 months ago
Test name Executions per second
[...array].sort 409.8 Ops/sec
array.toSorted 413.1 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)