es-toolkit/benchmarks/performance/orderBy.bench.ts
Dayong Lee bf33cfbca5
feat(orderBy, isSymbol): add compatibility with lodash (#357)
* Add internal functions

* add orderBy with compat

* Add docs

* Fix typo

* Split the code for readability

* Change convert to path logic and variable name for readability

* Add test cases and js doc in isKey and isSymbol

* Add testcase and change logic of isKey

* change bench category name

* split converToPropertyName for testing

* Add case for coverage

* fix type

* Change using getTage to instanceof

* move to predicate

* Add doc

* Add bench and description in isSymbol

* Fix type and test case

* Simplify function names

* Feat: handle the deep path like keys
2024-08-10 16:30:32 +09:00

47 lines
1.4 KiB
TypeScript

import { bench, describe } from 'vitest';
import { orderBy as orderByToolkit } from 'es-toolkit';
import { orderBy as orderByToolkitCompat } from 'es-toolkit/compat';
import { orderBy as orderByLodash } from 'lodash';
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'];
const orders: Array<'asc' | 'desc'> = ['asc', 'desc'];
describe('orderBy', () => {
bench('es-toolkit/orderBy', () => {
orderByToolkit(users, keys, orders);
});
bench('es-toolkit/compat/orderBy', () => {
orderByToolkitCompat(users, keys, orders);
});
bench('lodash/orderBy', () => {
orderByLodash(users, keys, orders);
});
});
describe('orderBy (nested property names)', () => {
bench('es-toolkit/compat/orderBy', () => {
orderByToolkitCompat(users, [['nested', 'user'], ['age']], orders);
});
bench('lodash/orderBy', () => {
orderByLodash(users, [['nested', 'user'], ['age']], orders);
});
});
describe('orderBy (property path)', () => {
bench('es-toolkit/compat/orderBy', () => {
orderByToolkitCompat(users, ['nested.user', 'age'], orders);
});
bench('lodash/orderBy', () => {
orderByLodash(users, ['nested.user', 'age'], orders);
});
});