Skip to content

Commit a8da230

Browse files
authored
chore: Infra benchmarks boilerplate (#1088)
1 parent c79e168 commit a8da230

File tree

5 files changed

+189
-145
lines changed

5 files changed

+189
-145
lines changed

apps/infra-benchmarks/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "infra-benchmarks",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"discriminated-union": "node --experimental-strip-types --expose-gc src/discriminated-union.ts"
7+
},
8+
"license": "MIT",
9+
"devDependencies": {
10+
"tinybench": "^3.1.0"
11+
},
12+
"packageManager": "[email protected]+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af"
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Bench } from 'tinybench';
2+
3+
const bench = new Bench({
4+
name: 'discriminated union',
5+
time: 100,
6+
async setup() {
7+
// biome-ignore lint/suspicious/noExplicitAny: <making sure GC has no impact on the results>
8+
(globalThis as any).gc();
9+
},
10+
});
11+
12+
bench
13+
.add('string tags', () => {
14+
console.log('I am faster');
15+
})
16+
.add('slower task', async () => {
17+
await new Promise((resolve) => setTimeout(resolve, 1)); // we wait 1ms :)
18+
console.log('I am slower');
19+
});
20+
21+
await bench.run();
22+
23+
console.log(bench.name);
24+
console.table(bench.table());

0 commit comments

Comments
 (0)