Skip to content

Commit 3285105

Browse files
committed
do not mutate array
1 parent 1f00dca commit 3285105

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

test/benchmarks/driver_bench/src/main.mts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,33 @@ function calculateCompositeBenchmarks(results: MetricInfo[]) {
201201
function calculateNormalizedResults(results: MetricInfo[]): MetricInfo[] {
202202
const primesBench = results.find(r => r.info.test_name === 'primes');
203203
const pingBench = results.find(r => r.info.test_name === 'ping');
204-
let pingMegabytesPerSecond: number;
205204

206205
if (pingBench) {
206+
const newMetrics: MetricInfo[] = [];
207207
const pingThroughput = pingBench.metrics[0].value;
208208
for (const bench of results) {
209-
if (bench.info.test_name === 'primes' || bench.info.test_name === 'ping') continue;
210-
const normalizedThroughput = bench.metrics[0].value / pingThroughput;
211-
bench.metrics.push({name: 'normalized_throughput', value: normalizedThroughput});
212-
209+
if (bench.info.test_name === 'primes') {
210+
newMetrics.push({ ...bench });
211+
}
212+
else if (bench.info.test_name === 'ping') {
213+
// Compute ping's normalized_throughput against the primes bench if present
214+
if (primesBench) {
215+
const primesThroughput = primesBench.metrics[0].value;
216+
const normalizedThroughput: Metric = { 'name': 'normalized_throughput', value: bench.metrics[0].value / primesThroughput };
217+
const newInfo: MetricInfo = { info: { ...bench.info }, metrics: [...bench.metrics, normalizedThroughput] };
218+
newMetrics.push(newInfo);
219+
} else {
220+
newMetrics.push({ ...bench });
221+
}
222+
} else {
223+
// Compute normalized_throughput of benchmarks against ping bench
224+
const normalizedThroughput: Metric = { 'name': 'normalized_throughput', value: bench.metrics[0].value / pingThroughput };
225+
const newInfo: MetricInfo = { info: { ...bench.info }, metrics: [...bench.metrics, normalizedThroughput] }
226+
newMetrics.push(newInfo);
227+
}
213228
}
214229

215-
if (primesBench) {
216-
const normalizedThroughput = pingBench.metrics[0].value / primesBench.metrics[0].value;
217-
pingMegabytesPerSecond = pingBench.metrics[0].value;
218-
pingBench.metrics.push({ name: 'normalized_throughput', value: normalizedThroughput });
219-
}
230+
return newMetrics;
220231
}
221232

222233
return results;

test/benchmarks/driver_bench/src/runner.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type BenchmarkModule = {
1717
tags?: string[];
1818
};
1919

20+
2021
const benchmarkName = snakeToCamel(path.basename(benchmarkFile, '.mjs'));
2122
const benchmark: BenchmarkModule = await import(`./${benchmarkFile}`);
2223

@@ -80,6 +81,7 @@ function percentileIndex(percentile: number, count: number) {
8081

8182
const medianExecution = durations[percentileIndex(50, count)];
8283
const megabytesPerSecond = benchmark.taskSize / medianExecution;
84+
const tags = benchmark.tags;
8385

8486
console.log(
8587
' '.repeat(3),
@@ -92,6 +94,6 @@ console.log(
9294

9395
await fs.writeFile(
9496
`results_${path.basename(benchmarkFile, '.mjs')}.json`,
95-
JSON.stringify(metrics(benchmarkName, megabytesPerSecond), undefined, 2) + '\n',
97+
JSON.stringify(metrics(benchmarkName, megabytesPerSecond, tags), undefined, 2) + '\n',
9698
'utf8'
9799
);

0 commit comments

Comments
 (0)