|
| 1 | +import assert from 'node:assert'; |
1 | 2 | import path from 'node:path'; |
2 | 3 |
|
3 | 4 | import { getArguments } from './args.js'; |
| 5 | +import { maxTime, memorySamplesPerBenchmark, minSamples } from './config.js'; |
4 | 6 | import { cyan, printBenchmarkResults, red } from './output.js'; |
5 | 7 | import { prepareBenchmarkProjects } from './projects.js'; |
6 | | -import { collectMemorySamples, collectTimingSamples } from './sampling.js'; |
7 | 8 | import { computeStats } from './statistics.js'; |
8 | 9 | import type { BenchmarkProject, BenchmarkResult } from './types.js'; |
9 | | -import { getBenchmarkName } from './workers.js'; |
| 10 | +import { |
| 11 | + getBenchmarkName, |
| 12 | + sampleMemoryModule, |
| 13 | + sampleTimingModule, |
| 14 | +} from './workers.js'; |
10 | 15 |
|
11 | 16 | export function runBenchmarks(): void { |
12 | 17 | // Get the revisions and make things happen! |
@@ -49,3 +54,31 @@ function runBenchmark( |
49 | 54 | printBenchmarkResults(results); |
50 | 55 | console.log(''); |
51 | 56 | } |
| 57 | + |
| 58 | +export function collectTimingSamples(modulePath: string): Array<number> { |
| 59 | + const samples: Array<number> = []; |
| 60 | + |
| 61 | + // If time permits, increase sample size to reduce the margin of error. |
| 62 | + const start = Date.now(); |
| 63 | + while (samples.length < minSamples || (Date.now() - start) / 1e3 < maxTime) { |
| 64 | + const sample = sampleTimingModule(modulePath); |
| 65 | + |
| 66 | + assert(sample > 0); |
| 67 | + samples.push(sample); |
| 68 | + } |
| 69 | + return samples; |
| 70 | +} |
| 71 | + |
| 72 | +export function collectMemorySamples(modulePath: string): Array<number> { |
| 73 | + const samples: Array<number> = []; |
| 74 | + for ( |
| 75 | + let sampleIndex = 0; |
| 76 | + sampleIndex < memorySamplesPerBenchmark; |
| 77 | + ++sampleIndex |
| 78 | + ) { |
| 79 | + const sample = sampleMemoryModule(modulePath); |
| 80 | + assert(sample > 0); |
| 81 | + samples.push(sample); |
| 82 | + } |
| 83 | + return samples; |
| 84 | +} |
0 commit comments