Skip to content

Commit 4096256

Browse files
committed
chore: improve final print, sort, and predict finish time
1 parent 908647b commit 4096256

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

test/benchmarks/driver_bench/src/main.mts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ import {
1818
} from './driver.mjs';
1919

2020
const __dirname = import.meta.dirname;
21-
const alphabetically = (a: string, b: string) => String.prototype.localeCompare.call(a, b);
21+
22+
export const alphabetically = (a: unknown, b: unknown) => {
23+
const res = `${a}`.localeCompare(`${b}`, 'en-US', {
24+
usage: 'sort',
25+
numeric: true,
26+
ignorePunctuation: false
27+
});
28+
return res < 0 ? -1 : res > 0 ? 1 : 0;
29+
};
2230

2331
/** Find every mjs file in the suites folder */
24-
async function getBenchmarks(): Promise<
25-
Record<string, Record<string, { benchFile: string } & Record<string, any>>>
26-
> {
32+
async function getBenchmarks(): Promise<{
33+
tests: Record<string, Record<string, { benchFile: string } & Record<string, any>>>;
34+
total: number;
35+
}> {
36+
let total = 0;
2737
const tests: Record<
2838
string,
2939
Record<string, { benchFile: string } & Record<string, any>>
@@ -39,15 +49,21 @@ async function getBenchmarks(): Promise<
3949
if (!benchmark.endsWith('.mjs')) continue;
4050
tests[suite] ??= Object.create(null);
4151
tests[suite][benchmark] = { benchFile: path.join('suites', suite, benchmark) };
52+
total += 1;
4253
}
4354
}
44-
return tests;
55+
return { tests, total };
4556
}
4657

4758
const hw = os.cpus();
4859
const ram = os.totalmem() / 1024 ** 3;
4960
const platform = { name: hw[0].model, cores: hw.length, ram: `${ram}GB` };
5061

62+
const { tests, total } = await getBenchmarks();
63+
64+
const earliest = new Date(Date.now() + total * 60 * 1000); // plus one min per bench
65+
const latest = new Date(Date.now() + total * 6 * 60 * 1000); // plus six min per bench (if we overshoot the 5 min limit)
66+
5167
const systemInfo = () =>
5268
[
5369
`\n- cpu: ${platform.name}`,
@@ -56,14 +72,15 @@ const systemInfo = () =>
5672
`- os: ${process.platform} (${os.release()})`,
5773
`- ram: ${platform.ram}`,
5874
`- node: ${process.version}`,
75+
`- running ${total} benchmarks`,
76+
` - finishes soonest: ${earliest.toLocaleTimeString('en-US', { timeZoneName: 'short' })} latest ${latest.toLocaleTimeString('en-US', { timeZoneName: 'short' })}`,
5977
`- driver: ${MONGODB_DRIVER_VERSION} (${MONGODB_DRIVER_REVISION}): ${MONGODB_DRIVER_PATH}`,
6078
` - options ${util.inspect(MONGODB_CLIENT_OPTIONS)}`,
6179
`- bson: ${MONGODB_BSON_VERSION} (${MONGODB_BSON_REVISION}): (${MONGODB_BSON_PATH})\n`
6280
].join('\n');
6381

6482
console.log(systemInfo());
6583

66-
const tests = await getBenchmarks();
6784
const runnerPath = path.join(__dirname, 'runner.mjs');
6885

6986
const results = [];

test/benchmarks/driver_bench/src/runner.mts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ do {
6969
if (totalDuration < ONE_MIN) continue;
7070

7171
// 100 runs OR five minutes
72-
if (count > 100 || totalDuration > FIVE_MIN) break;
72+
if (count >= 100 || totalDuration >= FIVE_MIN) break;
7373

7474
// count exceeds data space, we never intend to have more than a million data points let alone 10M
7575
if (count === data.length) break;
@@ -91,18 +91,11 @@ const medianExecution = durations[percentileIndex(50, count)];
9191
const megabytesPerSecond = benchmark.taskSize / medianExecution;
9292

9393
console.log(
94-
' ',
95-
benchmarkName,
96-
'finished in',
97-
totalDuration,
98-
'sec and ran',
99-
count,
100-
'iterations.',
101-
'median exec time',
102-
medianExecution,
103-
'sec',
104-
megabytesPerSecond,
105-
'mb/sec'
94+
' '.repeat(3),
95+
...['total time:', totalDuration, 'sec,'],
96+
...['ran:', count, 'times,'],
97+
...['time per run:', medianExecution, 'sec,'],
98+
...['throughput:', megabytesPerSecond, 'mb/sec']
10699
);
107100

108101
await fs.writeFile(

0 commit comments

Comments
 (0)