-
-
Notifications
You must be signed in to change notification settings - Fork 72
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 performance test #253
Comments
Nice to haves would be:
|
const cn1 =
"flex w-full justify-between rounded-lg bg-purple-100 px-4 py-2 text-left text-sm font-medium text-purple-900 hover:bg-purple-200 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75";
const cn2 =
"flex w-full justify-between rounded-lg bg-purple-100 px-4 py-2 text-left text-sm font-medium text-purple-900 hover:bg-purple-200 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75";
const cn3 = "flex items-center w-full justify-between tracking-0_2 hover:bg-gray-500 cursor-pointer px-16 px-24";
let start = performance.now();
twMerge(
cn1,
cn2,
cn3,
);
let end = performance.now();
console.log(`Execution time: ${end - start} ms`);
//classNames test
classNames(
cn1,
cn2,
cn3,
); for a big page that can easily have thousands of DOM nodes, that will be slow. due to the performance concern, we can not recommend |
Hey @larry-cedar! 👋 tailwind-merge computes a large data structure on the first call to const cn1 =
"flex w-full justify-between rounded-lg bg-purple-100 px-4 py-2 text-left text-sm font-medium text-purple-900 hover:bg-purple-200 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75";
const cn2 =
"flex w-full justify-between rounded-lg bg-purple-100 px-4 py-2 text-left text-sm font-medium text-purple-900 hover:bg-purple-200 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75";
const cn3 = "flex items-center w-full justify-between tracking-0_2 hover:bg-gray-500 cursor-pointer px-16 px-24";
let twMergeStart = performance.now();
for (let i = 0; i < 1000; i++) {
twMerge(
cn1,
cn2,
cn3,
);
}
let twMergeEnd = performance.now();
console.log(`twMerge execution time: ${twMergeEnd - twMergeStart} ms`);
let classNamesStart = performance.now();
for (let i = 0; i < 1000; i++) {
classNames(
cn1,
cn2,
cn3,
);
}
let classNamesEnd = performance.now();
console.log(`classNames execution time: ${classNamesEnd - classNamesStart} ms`); But that comparison is still not very realistic because I wrote about a realistic test case here: #243 (comment)
|
Hey @dcastil thanks for your reply. I see |
There's no way of making the first call faster at the moment unfortunately. You can check out some alternatives to tailwind-merge here: https://github.com/dcastil/tailwind-merge/blob/v1.13.2/docs/when-and-how-to-use-it.md#alternatives |
Research: What I want
Github Action
Data
|
Interesting article checking whether GitHub Action runners are good enough for benchmarking: https://labs.quansight.org/blog/2021/08/github-actions-benchmarks |
@rortan134 created a benchmark in https://github.com/rortan134/tailwind-merge/blob/benchmark/tests/benchmark.bench.ts as part of #445 which I could use. Full code: import { benchmarkSuite } from 'jest-bench' // v^29.7.1
import { createTailwindMerge, createTailwindMerge2 } from '../src'
const tailwindMerge = createTailwindMerge(() => ({
cacheSize: 20,
separator: ':',
theme: {},
classGroups: {
fooKey: [{ fooKey: ['bar', 'baz'] }],
fooKey2: [{ fooKey: ['qux', 'quux'] }, 'other-2'],
otherKey: ['nother', 'group'],
},
conflictingClassGroups: {
fooKey: ['otherKey'],
otherKey: ['fooKey', 'fooKey2'],
},
conflictingClassGroupModifiers: {},
}))
const tailwindMerge2 = createTailwindMerge2(() => ({
cacheSize: 20,
separator: ':',
theme: {},
classGroups: {
fooKey: [{ fooKey: ['bar', 'baz'] }],
fooKey2: [{ fooKey: ['qux', 'quux'] }, 'other-2'],
otherKey: ['nother', 'group'],
},
conflictingClassGroups: {
fooKey: ['otherKey'],
otherKey: ['fooKey', 'fooKey2'],
},
conflictingClassGroupModifiers: {},
}))
benchmarkSuite('createTailwindMerge', {
setup() {},
'v1': () => {
tailwindMerge('my-modifier:fooKey-bar my-modifier:fooKey-baz')
},
'v2': () => {
tailwindMerge2('my-modifier:fooKey-bar my-modifier:fooKey-baz')
},
}) |
@XantreDev that would be nice indeed! I didn't know of Codspeed and really like how they solve the problem with fluctuating performance on shared vCPUs. Feel free to submit a PR. I can set up an account on CodSpeed. Here is a data set from real |
I just created an account on Codspeed and added the Codspeed token to the repository secrets. It should be possible to access it as |
Thanks. I will implement it soon |
This was addressed in release v2.5.3. |
Discussed in #252
Originally posted by tordans June 15, 2023
It would be awesome to have the performance test that clsx uses run for
twMerge
andtwJoin
and have a page in the repo that shows the results.I found existing references to performance, but in the end they do not really tell me how the libraries compare.
The text was updated successfully, but these errors were encountered: