fast-sort
Blazing fast array sorting that outperforms lodash sorting by ~2x (in some cases it's more then 5x).
Take a look at the benchmark section for more information about performance.
fast-sort is part of js-flock library exported as single module. check js-flock for more cool modules.
Capabilities
- Sorting array of objects (supports comparing by nested object properties)
- Sorting flat arrays
- Sorting by multiple properties
- Undefined and null values are always sorted to bottom of list no matter if ordering is ascending or descending.
- Mutates input array in a same way as native Array.prototype.sort() does.
Example
import sort from 'fast-sort';
sort([1,4,2]).asc();
sort([1,4,2]).desc();
sort(persons).asc((p) => p.firstName.toLowerCase());
sort(persons).desc([
(p) => p.firstName,
(p) => p.lastName,
(p) => p.dob
]);
sort(null).asc();
sort(33).desc();
Including module
import sort from 'fast-sort';
import sort from 'fast-sort/sort.es5';
import sort from 'fast-sort/sort.es5.min';
fast-sort is part of js-flock library and can be included throught js-flock.
import sort from 'js-flock/sort';
import sort from 'js-flock/es5/sort';
import sort from 'js-flock/es5/sort.min';
Benchmark
Benchmarking sort is not an easy task as there is so many different scenarios that can happen while sorting.
Because of that 5 different benchmarks have been created to test how fast-sort is behaving on different inputs and sort scenarios.
Each benchmark is run with different array sizes from small 100 items to large 100 000 items.
Every run of benchmark outputs different results but the results are constantly better then lodash sort and in following benchmark score ranges from 1.37x to 13.51x faster then lodash sort. This will vary on each benchmark run but it should not vary too much.
Benchmark scores
Benchmark has been run on:
- 16 GB Ram
- Intel® Core™ i5-4570 CPU @ 3.20GHz × 4
- Ubuntu 16.04
- Node 6.9.2
fast-sort benchmark result are represent with flock name and is colored in blue.
Running benchmark
To run benchmark on your PC follow steps from below
- git clone https://github.com/snovakovic/js-flock.git
- cd js-flock
- npm install
- npm run benchmark:sort
In case you notice any irregularities in benchmark or you want to add sort library to benchmark score
please open issue here