Skip to content

Commit

Permalink
add temporary instrumentation to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Aug 18, 2024
1 parent e54289b commit a7fb764
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/tw-merge.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ClassNameValue, extendTailwindMerge } from '../src'

import testData from './tw-merge-benchmark-data.json'

console.log('CI env variable:', JSON.stringify(process.env.CI))

Check warning on line 7 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 7 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

describe('twMerge', () => {
bench('init', () => {
const twMerge = extendTailwindMerge({})
Expand All @@ -12,10 +14,17 @@ describe('twMerge', () => {

for (const isCached of [true, false]) {
describe(isCached ? 'cached' : 'uncached', () => {
let consoleIndex = 0

let twMerge: (...classLists: ClassNameValue[]) => string

function setup(task: BenchTask) {
task.opts.beforeEach = function beforeEach() {
if (consoleIndex < 100) {
console.log('setup beforeEach')

Check warning on line 24 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 24 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
consoleIndex++
}

twMerge = extendTailwindMerge({
cacheSize: isCached ? undefined : 0,
})
Expand All @@ -37,6 +46,11 @@ describe('twMerge', () => {
if (process.env.CI) {
// codespeed tries to optimize function, before actual setup call - we need to adopt
beforeEach(() => {
if (consoleIndex < 100) {
console.log('beforeEach')

Check warning on line 50 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 50 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
consoleIndex++
}

twMerge = extendTailwindMerge({
cacheSize: isCached ? undefined : 0,
})
Expand All @@ -48,6 +62,11 @@ describe('twMerge', () => {
bench(
withSuffix('simple'),
() => {
if (consoleIndex < 100) {
console.log('simple')

Check warning on line 66 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 66 in tests/tw-merge.benchmark.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
consoleIndex++
}

twMerge('flex mx-10 px-10', 'mr-5 pr-5')
},
options,
Expand Down

0 comments on commit a7fb764

Please sign in to comment.