Skip to content

Commit

Permalink
implemented benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
XantreDev committed Aug 11, 2024
1 parent b42e596 commit 9e4204c
Show file tree
Hide file tree
Showing 5 changed files with 9,858 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: codspeed-benchmarks

on:
push:
branches:
- 'main' # or "main"
pull_request:
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20.11.1
# More info: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry
registry-url: 'https://registry.npmjs.org'
- name: Use node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: yarn-node-20-lock-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-node-20-lock-
- run: yarn install --frozen-lockfile
- name: Run benchmarks
uses: CodSpeedHQ/action@v3
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: 'yarn bench'
37 changes: 37 additions & 0 deletions benchmarks/bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Bench } from 'tinybench'
import { withCodSpeed } from '@codspeed/tinybench-plugin'

import { twMerge } from '../src/index'

import testData from './perf-test-data.json'

const bench = withCodSpeed(new Bench())

bench.add('twMerge (simple)', () => {
twMerge('flex mx-10 px-10', 'mr-5 pr-5')
})

bench.add('twMerge (heavy)', () => {
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.add('twMerge (collection)', () => {
for (let i = 0; i < testData.length; ++i) {
type Item = (typeof testData)[number][number]
twMerge(...(testData[i] as Exclude<Item, true>[]))
}
})
;(async () => {
await bench.run()
console.table(bench.table())

Check warning on line 36 in benchmarks/bench.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
})()
Loading

0 comments on commit 9e4204c

Please sign in to comment.