Skip to content

Commit bb8cd02

Browse files
AlpAlp
authored andcommitted
test: replace benchmark test with vitest bench script
Use vitest bench for proper statistical benchmarking instead of a test. Run with: npx vitest bench Results on synthetic monorepo (500+ files): targeted: 2.12ms (471 ops/s) eager: 99.3ms (10 ops/s) 46.83x faster
1 parent 55eff4b commit bb8cd02

File tree

2 files changed

+42
-97
lines changed

2 files changed

+42
-97
lines changed

tests/benchmark.bench.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as path from 'node:path';
2+
import {Project} from 'ts-morph';
3+
import {bench, describe} from 'vitest';
4+
import {
5+
addSourceFilesFromTsConfigSafe,
6+
ensureSourceFileInProject,
7+
} from '../src/cli/ts-project';
8+
import {discoverAllTsConfigs} from '../src/cli/tsconfig';
9+
10+
const fixtureRoot = path.resolve(
11+
__dirname,
12+
'benchmarks/synthetic-monorepo/tsconfig.json',
13+
);
14+
const schemaConfigFile = path.resolve(
15+
__dirname,
16+
'benchmarks/synthetic-monorepo/schema/drizzle-zero.config.ts',
17+
);
18+
19+
describe('file loading', () => {
20+
bench('eager: load all files from all tsconfigs', async () => {
21+
const allTsConfigPaths = await discoverAllTsConfigs(fixtureRoot);
22+
const project = new Project({
23+
tsConfigFilePath: fixtureRoot,
24+
skipAddingFilesFromTsConfig: true,
25+
});
26+
for (const tsConfigPath of allTsConfigPaths) {
27+
addSourceFilesFromTsConfigSafe({tsProject: project, tsConfigPath});
28+
}
29+
});
30+
31+
bench('targeted: load only the requested file', async () => {
32+
const project = new Project({
33+
tsConfigFilePath: fixtureRoot,
34+
skipAddingFilesFromTsConfig: true,
35+
});
36+
ensureSourceFileInProject({
37+
tsProject: project,
38+
filePath: schemaConfigFile,
39+
debug: false,
40+
});
41+
});
42+
});

tests/benchmark.test.ts

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)