Skip to content

Commit de0f3a5

Browse files
authored
refactor(benchmark): integrate run + sampling files (#4683)
1 parent d9f43c8 commit de0f3a5

2 files changed

Lines changed: 35 additions & 34 deletions

File tree

resources/benchmark/run.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import assert from 'node:assert';
12
import path from 'node:path';
23

34
import { getArguments } from './args.js';
5+
import { maxTime, memorySamplesPerBenchmark, minSamples } from './config.js';
46
import { cyan, printBenchmarkResults, red } from './output.js';
57
import { prepareBenchmarkProjects } from './projects.js';
6-
import { collectMemorySamples, collectTimingSamples } from './sampling.js';
78
import { computeStats } from './statistics.js';
89
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';
1015

1116
export function runBenchmarks(): void {
1217
// Get the revisions and make things happen!
@@ -49,3 +54,31 @@ function runBenchmark(
4954
printBenchmarkResults(results);
5055
console.log('');
5156
}
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+
}

resources/benchmark/sampling.ts

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

0 commit comments

Comments
 (0)