Skip to content

Commit d588afd

Browse files
AlpAlp
authored andcommitted
bench: end-to-end generate benchmark using vitest bench
Benchmarks the actual CLI generate command against the synthetic monorepo fixture. Run with: npx vitest bench
1 parent bb8cd02 commit d588afd

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

tests/benchmark.bench.ts

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,19 @@
1+
import {execSync} from 'node:child_process';
12
import * as path from 'node:path';
2-
import {Project} from 'ts-morph';
33
import {bench, describe} from 'vitest';
4-
import {
5-
addSourceFilesFromTsConfigSafe,
6-
ensureSourceFileInProject,
7-
} from '../src/cli/ts-project';
8-
import {discoverAllTsConfigs} from '../src/cli/tsconfig';
94

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-
);
5+
const cliPath = path.resolve(__dirname, '../dist/cli/index.js');
6+
const fixtureDir = path.resolve(__dirname, 'benchmarks/synthetic-monorepo');
187

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-
});
8+
describe('generate', () => {
9+
bench(
10+
'end-to-end generate on synthetic monorepo',
11+
() => {
12+
execSync(
13+
`node ${cliPath} generate --config schema/drizzle-zero.config.ts --output /tmp/drizzle-zero-bench-output.ts --suppress-defaults-warning --force`,
14+
{cwd: fixtureDir, stdio: 'ignore'},
15+
);
16+
},
17+
{warmupIterations: 1, iterations: 5, time: 0},
18+
);
4219
});

tests/benchmarks/synthetic-monorepo/schema/drizzle-zero.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { drizzleZeroConfig } from "../../src";
1+
import { drizzleZeroConfig } from "drizzle-zero";
22
import * as schema from "./schema";
33

44
export default drizzleZeroConfig(schema, {

0 commit comments

Comments
 (0)