Skip to content

Commit 628a126

Browse files
authored
internal: read benchmark names through dedicated worker (#4679)
previously, we ran a sampling benchmark just to retrieve the name
1 parent 7bfcc49 commit 628a126

6 files changed

Lines changed: 21 additions & 7 deletions

File tree

resources/benchmark/run.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import path from 'node:path';
33
import { getArguments } from './args.js';
44
import { cyan, printBenchmarkResults, red } from './output.js';
55
import { prepareBenchmarkProjects } from './projects.js';
6-
import { collectSamples, sampleModule } from './sampling.js';
6+
import { collectSamples } from './sampling.js';
77
import { computeStats } from './statistics.js';
88
import type { BenchmarkProject, BenchmarkResult } from './types.js';
9+
import { getBenchmarkName } from './workers.js';
910

1011
export function runBenchmarks(): void {
1112
// Get the revisions and make things happen!
@@ -28,8 +29,7 @@ function runBenchmark(
2829
const modulePath = path.join(projectPath, benchmark);
2930

3031
if (i === 0) {
31-
const { name } = sampleModule(modulePath);
32-
console.log('\u23F1 ' + name);
32+
console.log('\u23F1 ' + getBenchmarkName(modulePath));
3333
}
3434

3535
try {

resources/benchmark/sampling.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { yellow } from './output.js';
55
import type { BenchmarkSample } from './types.js';
66
import { sampleModule } from './workers.js';
77

8-
export { sampleModule };
9-
108
export function collectSamples(modulePath: string): Array<BenchmarkSample> {
119
let numOfConsequentlyRejectedSamples = 0;
1210
const samples: Array<BenchmarkSample> = [];

resources/benchmark/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export interface BenchmarkProject {
44
}
55

66
export interface BenchmarkSample {
7-
name: string;
87
clocked: number;
98
memUsed: number;
109
involuntaryContextSwitches: number;

resources/benchmark/worker-name.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {
2+
loadBenchmark,
3+
readModulePath,
4+
runWorker,
5+
writeResult,
6+
} from './worker-utils.js';
7+
8+
runWorker(async () => {
9+
const benchmark = await loadBenchmark(readModulePath());
10+
writeResult(benchmark.name);
11+
});

resources/benchmark/worker-timing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ runWorker(async () => {
2121
const resourcesEnd = process.resourceUsage();
2222

2323
writeResult({
24-
name: benchmark.name,
2524
clocked: timeDiff / benchmark.count,
2625
memUsed: (process.memoryUsage().heapUsed - memBaseline) / benchmark.count,
2726
involuntaryContextSwitches:

resources/benchmark/workers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { localRepoPath } from '../utils.js';
66
import { nodeFlags } from './config.js';
77
import type { BenchmarkSample } from './types.js';
88

9+
export function getBenchmarkName(modulePath: string): string {
10+
return runWorkerFile(
11+
localRepoPath('resources/benchmark/worker-name.js'),
12+
modulePath,
13+
) as string;
14+
}
15+
916
export function sampleModule(modulePath: string): BenchmarkSample {
1017
return runWorkerFile(
1118
localRepoPath('resources/benchmark/worker-timing.js'),

0 commit comments

Comments
 (0)