forked from dcastil/tailwind-merge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tw-merge.benchmark.ts
54 lines (41 loc) · 1.63 KB
/
tw-merge.benchmark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { bench, describe } from 'vitest'
import { extendTailwindMerge } from '../src'
import testDataCollection from './tw-merge-benchmark-data.json'
type TestDataItem = Exclude<(typeof testDataCollection)[number][number], true>[]
describe('twMerge', () => {
bench('init', () => {
const twMerge = extendTailwindMerge({})
twMerge()
})
bench('simple', () => {
const twMerge = extendTailwindMerge({})
twMerge('flex mx-10 px-10', 'mr-5 pr-5')
})
bench('heavy', () => {
const twMerge = extendTailwindMerge({})
twMerge(
'font-medium text-sm leading-16',
'group/button relative isolate items-center justify-center overflow-hidden rounded-md outline-none transition [-webkit-app-region:no-drag] focus-visible:ring focus-visible:ring-primary',
'inline-flex',
'bg-primary-50 ring ring-primary-200',
'text-primary dark:text-primary-900 hover:bg-primary-100',
false,
'font-medium text-sm leading-16 gap-4 px-6 py-4',
null,
'p-0 size-24',
null,
)
})
bench('collection with cache', () => {
const twMerge = extendTailwindMerge({})
for (let index = 0; index < testDataCollection.length; ++index) {
twMerge(...(testDataCollection[index] as TestDataItem))
}
})
bench('collection without cache', () => {
const twMerge = extendTailwindMerge({ cacheSize: 0 })
for (let index = 0; index < testDataCollection.length; ++index) {
twMerge(...(testDataCollection[index] as TestDataItem))
}
})
})