Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions test/benchmarks/driver_bench/src/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ import {
} from './driver.mjs';

const __dirname = import.meta.dirname;
const alphabetically = (a: string, b: string) => String.prototype.localeCompare.call(a, b);

export const alphabetically = (a: unknown, b: unknown) => {
const res = `${a}`.localeCompare(`${b}`, 'en-US', {
usage: 'sort',
numeric: true,
ignorePunctuation: false
});
return res < 0 ? -1 : res > 0 ? 1 : 0;
};

/** Find every mjs file in the suites folder */
async function getBenchmarks(): Promise<
Record<string, Record<string, { benchFile: string } & Record<string, any>>>
> {
async function getBenchmarks(): Promise<{
tests: Record<string, Record<string, { benchFile: string } & Record<string, any>>>;
total: number;
}> {
let total = 0;
const tests: Record<
string,
Record<string, { benchFile: string } & Record<string, any>>
Expand All @@ -39,15 +49,21 @@ async function getBenchmarks(): Promise<
if (!benchmark.endsWith('.mjs')) continue;
tests[suite] ??= Object.create(null);
tests[suite][benchmark] = { benchFile: path.join('suites', suite, benchmark) };
total += 1;
}
}
return tests;
return { tests, total };
}

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

const { tests, total } = await getBenchmarks();

const earliest = new Date(Date.now() + total * 60 * 1000); // plus one min per bench
const latest = new Date(Date.now() + total * 6 * 60 * 1000); // plus six min per bench (if we overshoot the 5 min limit)

const systemInfo = () =>
[
`\n- cpu: ${platform.name}`,
Expand All @@ -56,14 +72,15 @@ const systemInfo = () =>
`- os: ${process.platform} (${os.release()})`,
`- ram: ${platform.ram}`,
`- node: ${process.version}`,
`- running ${total} benchmarks`,
` - finishes soonest: ${earliest.toLocaleTimeString('en-US', { timeZoneName: 'short' })} latest ${latest.toLocaleTimeString('en-US', { timeZoneName: 'short' })}`,
`- driver: ${MONGODB_DRIVER_VERSION} (${MONGODB_DRIVER_REVISION}): ${MONGODB_DRIVER_PATH}`,
` - options ${util.inspect(MONGODB_CLIENT_OPTIONS)}`,
`- bson: ${MONGODB_BSON_VERSION} (${MONGODB_BSON_REVISION}): (${MONGODB_BSON_PATH})\n`
].join('\n');

console.log(systemInfo());

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

const results = [];
Expand Down
19 changes: 6 additions & 13 deletions test/benchmarks/driver_bench/src/runner.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ do {
if (totalDuration < ONE_MIN) continue;

// 100 runs OR five minutes
if (count > 100 || totalDuration > FIVE_MIN) break;
if (count >= 100 || totalDuration >= FIVE_MIN) break;

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

console.log(
' ',
benchmarkName,
'finished in',
totalDuration,
'sec and ran',
count,
'iterations.',
'median exec time',
medianExecution,
'sec',
megabytesPerSecond,
'mb/sec'
' '.repeat(3),
...['total time:', totalDuration, 'sec,'],
...['ran:', count, 'times,'],
...['time per run:', medianExecution, 'sec,'],
...['throughput:', megabytesPerSecond, 'mb/sec']
);

await fs.writeFile(
Expand Down