-
Notifications
You must be signed in to change notification settings - Fork 31
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
Tiny benchmarking harness #2699
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable no-console */ | ||
import { Bench } from 'tinybench'; | ||
|
||
import { splitDashedKey, splitDashedKeyIterative, splitDashedKeyRegex } from 'src/utils/splitDashedKey'; | ||
|
||
const inputs: string[] = ['mycomponent-0-1', 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6-100-200']; | ||
|
||
const bench = new Bench({ | ||
name: 'splitDashedKey benchmark', | ||
time: 100, | ||
setup: (_task, mode) => { | ||
// Run the garbage collector before warmup at each cycle | ||
if (mode === 'warmup' && typeof globalThis.gc === 'function') { | ||
globalThis.gc(); | ||
} | ||
}, | ||
}); | ||
|
||
for (const input of inputs) { | ||
bench | ||
.add(`[${input}] original`, () => splitDashedKey(input)) | ||
.add(`[${input}] regex`, () => splitDashedKeyRegex(input)) | ||
.add(`[${input}] iterative`, () => splitDashedKeyIterative(input)); | ||
} | ||
|
||
bench.run().then(() => { | ||
const table = bench.table(); | ||
|
||
console.log(bench.name); | ||
console.table(table); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"include": ["*.ts"], | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "Bundler", | ||
"noEmit": true, | ||
"noUncheckedIndexedAccess": true, | ||
"paths": { | ||
"src/*": ["../src/*"], | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
"tsc": "yarn gen && tsc && tsc --project test/tsconfig.json", | ||
"tsc:watch": "yarn gen && tsc --watch", | ||
"tsc:watch:cypress": "yarn gen && tsc --watch --project test/tsconfig.json", | ||
"lint": "yarn gen && eslint ." | ||
"lint": "yarn gen && eslint .", | ||
"bench": "tsx --expose_gc --tsconfig benchmarks/tsconfig.json benchmarks/${0}" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.25.8", | ||
|
@@ -112,10 +113,12 @@ | |
"source-map-loader": "5.0.0", | ||
"style-loader": "4.0.0", | ||
"terser-webpack-plugin": "5.3.10", | ||
"tinybench": "^3.0.3", | ||
"ts-jest": "29.2.5", | ||
"ts-loader": "9.5.1", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0", | ||
"tsx": "^4.19.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! 🤩 We already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oo didn't even notice, used |
||
"typescript-plugin-css-modules": "^5.1.0", | ||
"use-immer": "^0.10.0", | ||
"utility-types": "3.11.0", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into it, and while
tinybench
seems to work well enough for the example use-case here, it doesn't seem there's any straight-forward ways to benchmark react components (including re-rendering) with it. There are libraries to do that, some of which seems to spin up headless chrome to run their benchmark in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle I can't think of any reason why a React test renderer wouldn't run under NodeJS in this context when it is no problem in a jest testrunner? If it's practically much harder for some reason I'm not opposed to other tools at all, and I think we can even have multiple tools for different use-cases (though I have previously often just stuck to the same benchmarking harness for all level of benchmarks previously). But I think we should start to define a process around this to figure out