Exploring and challenging most sorting algorithms in javascript.
Below I will list the results of some tests ran on different benchmarks. What matters here is the size of the input array, and its content. As You will see comparing the outcomes of different node versions, the Array.prototype.sort
got better in the most recent one (actually from 11.x.x).
The strategy named native in the tables below is the Array.prototype.sort
function which turns surprisingly to not be the fastest solution, at least when not using an up to date node version. Another reason to keep your node up to date.
For curiosity I also added lodash using the _.sort_by function.
Env: MacBook Pro, 2.5 GHz Dual-Core Intel Core i7, 16 GB 2133 MHz LPDDR3
stats On node v10.14.1
- 100 elements [int, obj]
- 200 elements [int, obj]
- 500 elements [int, obj]
- 1000 elements [int, obj]
- 2000 elements [int, obj]
stats On node v12.16.1