|
12 | 12 | import fs from 'node:fs'; |
13 | 13 | import path from 'node:path'; |
14 | 14 | import { performance } from 'node:perf_hooks'; |
15 | | -import { fileURLToPath, pathToFileURL } from 'node:url'; |
| 15 | +import { fileURLToPath } from 'node:url'; |
16 | 16 | import Database from 'better-sqlite3'; |
| 17 | +import { resolveBenchmarkSource, srcImport } from './lib/bench-config.js'; |
17 | 18 |
|
18 | 19 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
19 | 20 | const root = path.resolve(__dirname, '..'); |
20 | 21 |
|
21 | | -// Read version from package.json |
22 | | -const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); |
| 22 | +const { version, srcDir, cleanup } = await resolveBenchmarkSource(); |
23 | 23 |
|
24 | 24 | const dbPath = path.join(root, '.codegraph', 'graph.db'); |
25 | 25 |
|
26 | 26 | // Import programmatic API (use file:// URLs for Windows compatibility) |
27 | | -const { buildGraph } = await import(pathToFileURL(path.join(root, 'src', 'builder.js')).href); |
| 27 | +const { buildGraph } = await import(srcImport(srcDir, 'builder.js')); |
28 | 28 | const { fnDepsData, fnImpactData, pathData, rolesData, statsData } = await import( |
29 | | - pathToFileURL(path.join(root, 'src', 'queries.js')).href |
| 29 | + srcImport(srcDir, 'queries.js') |
30 | 30 | ); |
31 | 31 | const { isNativeAvailable } = await import( |
32 | | - pathToFileURL(path.join(root, 'src', 'native.js')).href |
| 32 | + srcImport(srcDir, 'native.js') |
33 | 33 | ); |
34 | 34 |
|
35 | 35 | const INCREMENTAL_RUNS = 3; |
@@ -133,10 +133,10 @@ async function benchmarkEngine(engine) { |
133 | 133 | } |
134 | 134 |
|
135 | 135 | const queries = { |
136 | | - fnDepsMs: benchQuery(fnDepsData, targets.hub, dbPath, { depth: 3, noTests: true }), |
137 | | - fnImpactMs: benchQuery(fnImpactData, targets.hub, dbPath, { depth: 3, noTests: true }), |
138 | | - pathMs: benchQuery(pathData, targets.hub, targets.leaf, dbPath, { noTests: true }), |
139 | | - rolesMs: benchQuery(rolesData, dbPath, { noTests: true }), |
| 136 | + fnDepsMs: fnDepsData ? benchQuery(fnDepsData, targets.hub, dbPath, { depth: 3, noTests: true }) : null, |
| 137 | + fnImpactMs: fnImpactData ? benchQuery(fnImpactData, targets.hub, dbPath, { depth: 3, noTests: true }) : null, |
| 138 | + pathMs: pathData ? benchQuery(pathData, targets.hub, targets.leaf, dbPath, { noTests: true }) : null, |
| 139 | + rolesMs: rolesData ? benchQuery(rolesData, dbPath, { noTests: true }) : null, |
140 | 140 | }; |
141 | 141 |
|
142 | 142 | return { |
@@ -173,7 +173,7 @@ if (isNativeAvailable()) { |
173 | 173 | console.log = origLog; |
174 | 174 |
|
175 | 175 | const result = { |
176 | | - version: pkg.version, |
| 176 | + version, |
177 | 177 | date: new Date().toISOString().slice(0, 10), |
178 | 178 | files: wasm.files, |
179 | 179 | wasm: { |
@@ -205,3 +205,5 @@ const result = { |
205 | 205 | }; |
206 | 206 |
|
207 | 207 | console.log(JSON.stringify(result, null, 2)); |
| 208 | + |
| 209 | +cleanup(); |
0 commit comments