es-toolkit/benchmarks/performance/sortBy.bench.ts
Dayong Lee 21a0ceabc5
feat(sortBy): implement es-toolkit/sortBy (#381)
* Implement sortBy

* Add bench

* Extends template from object

* Fix example

* Add mixed iteratees

* Add docs and fix examples

* Fix jsdoc

* make prettier

* Update src/array/sortBy.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
2024-08-15 11:15:35 +09:00

23 lines
772 B
TypeScript

import { bench, describe } from 'vitest';
import { sortBy as sortByToolkit } from 'es-toolkit';
import { sortBy as sortByLodash } from 'lodash';
describe('sortBy', () => {
const users = [
{ user: 'fred', age: 48, nested: { user: 'fred' } },
{ user: 'barney', age: 34, nested: { user: 'barney' } },
{ user: 'fred', age: 40, nested: { user: 'fred' } },
{ user: 'barney', age: 36, nested: { user: 'bar' } },
];
const keys: Array<keyof (typeof users)[0]> = ['user', 'age'];
bench('es-toolkit/sortBy', () => {
sortByToolkit(users, keys);
sortByToolkit(users, [user => user.user, user => user.age]);
});
bench('lodash/sortBy', () => {
sortByLodash(users, keys);
sortByLodash(users, [user => user.user, user => user.age]);
});
});