Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort-on to benchmarks #48

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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