Skip to content

Commit

Permalink
Merge pull request #48 from LinusU/sort-on
Browse files Browse the repository at this point in the history
Add sort-on to benchmarks
  • Loading branch information
snovakovic authored Nov 10, 2021
2 parents 8638add + 457d519 commit 0bbd11f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions benchmark/implementations/deepObject.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fastSort = require('fast-sort');
const sortArray = require('sort-array');
const sortOn = require('sort-on');
const arraySort = require('array-sort');
const lodash = require('lodash');
const latestFastSortSort = require('../../dist/sort.js');
Expand All @@ -17,6 +18,7 @@ const sortImplementation = {
amount: p => p.level1.level2.amount,
},
}),
sortOn: (arr) => sortOn(arr, 'level1.level2.amount'),
arraySort: (arr) => arraySort(arr, 'level1.level2.amount'),
native: (arr) => arr.sort((a, b) => {
if (a.level1.level2.amount == null) return 1;
Expand Down
2 changes: 2 additions & 0 deletions benchmark/implementations/flatArray.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fastSort = require('fast-sort');
const arraySort = require('array-sort');
const sortArray = require('sort-array');
const sortOn = require('sort-on');
const lodash = require('lodash');
const latestFastSortSort = require('../../dist/sort.js');

Expand All @@ -12,6 +13,7 @@ const sortImplementation = {
lodash: (arr) => lodash.sortBy(arr),
arraySort: (arr) => arraySort(arr),
sortArray: (arr) => sortArray(arr),
sortOn: (arr) => sortOn(arr, x => x),
native: (arr) => arr.sort((a, b) => {
if (a == null) return 1;
if (b == null) return -1;
Expand Down
2 changes: 2 additions & 0 deletions benchmark/implementations/flatObject.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fastSort = require('fast-sort');
const sortArray = require('sort-array');
const sortOn = require('sort-on');
const arraySort = require('array-sort');
const lodash = require('lodash');
const latestFastSortSort = require('../../dist/sort.js');
Expand All @@ -11,6 +12,7 @@ const sortImplementation = {
latestFastSort: (arr) => latestFastSortSort(arr).asc('amount'),
lodash: (arr) => lodash.sortBy(arr, [(p) => p.amount]),
sortArray: (arr) => sortArray(arr, { by: 'amount', order: 'asc' }),
sortOn: (arr) => sortOn(arr, 'amount'),
arraySort: (arr) => arraySort(arr, 'amount'),
native: (arr) => arr.sort((a, b) => {
if (a.amount == null) return 1;
Expand Down
2 changes: 2 additions & 0 deletions benchmark/implementations/multiProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fastSort = require('fast-sort');
const arraySort = require('array-sort');
const lodash = require('lodash');
const sortArray = require('sort-array');
const sortOn = require('sort-on');
const latestFastSortSort = require('../../dist/sort.js');
const getRandomInt = require('../getRandomInt');

Expand All @@ -24,6 +25,7 @@ const sortImplementation = {
sortArray: (arr) => sortArray(arr, {
by: ['am1', 'am2'],
}),
sortOn: (arr) => sortOn(arr, ['am1', 'am2']),
};

module.exports.run = function({ size, numberOfRuns, librariesToRun }) {
Expand Down
1 change: 1 addition & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const librariesToRun = [
'lodash',
'arraySort',
'sortArray',
'sortOn',
'native',
];

Expand Down
27 changes: 27 additions & 0 deletions benchmark/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"fast-sort": "^2.0.0",
"lodash": "^4.17.21",
"single-line-log": "^1.1.2",
"sort-array": "^4.0.1"
"sort-array": "^4.0.1",
"sort-on": "^4.1.1"
},
"devDependencies": {},
"scripts": {
Expand Down

0 comments on commit 0bbd11f

Please sign in to comment.