Skip to content

Commit e7d289e

Browse files
add ms suffix to all duration variables
1 parent f54f54f commit e7d289e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

benchmarking/src/benchmarking.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import nodeFsPromises from "node:fs/promises";
33
import nodePath from "node:path";
44

55
export type FetchBenchmark = {
6-
calls: number[];
7-
average: number;
6+
callDurationsMs: number[];
7+
averageMs: number;
88
};
99

1010
export type BenchmarkingResults = {
@@ -40,13 +40,13 @@ export async function benchmarkApplicationResponseTime({
4040

4141
type BenchmarkFetchOptions = {
4242
numberOfCalls?: number;
43-
randomDelayMax?: number;
43+
maxRandomDelayMs?: number;
4444
fetch: (deploymentUrl: string) => Promise<Response>;
4545
};
4646

4747
const defaultOptions: Required<Omit<BenchmarkFetchOptions, "fetch">> = {
4848
numberOfCalls: 20,
49-
randomDelayMax: 15_000,
49+
maxRandomDelayMs: 15_000,
5050
};
5151

5252
/**
@@ -58,33 +58,33 @@ const defaultOptions: Required<Omit<BenchmarkFetchOptions, "fetch">> = {
5858
*/
5959
async function benchmarkFetch(url: string, options: BenchmarkFetchOptions): Promise<FetchBenchmark> {
6060
const benchmarkFetchCall = async () => {
61-
const preTime = performance.now();
61+
const preTimeMs = performance.now();
6262
const resp = await options.fetch(url);
63-
const postTime = performance.now();
63+
const postTimeMs = performance.now();
6464

6565
if (!resp.ok) {
6666
throw new Error(`Error: Failed to fetch from "${url}"`);
6767
}
6868

69-
return postTime - preTime;
69+
return postTimeMs - preTimeMs;
7070
};
7171

72-
const calls = await Promise.all(
72+
const callDurationsMs = await Promise.all(
7373
new Array(options?.numberOfCalls ?? defaultOptions.numberOfCalls).fill(null).map(async () => {
7474
// let's add a random delay before we make the fetch
7575
await nodeTimesPromises.setTimeout(
76-
Math.round(Math.random() * (options?.randomDelayMax ?? defaultOptions.randomDelayMax))
76+
Math.round(Math.random() * (options?.maxRandomDelayMs ?? defaultOptions.maxRandomDelayMs))
7777
);
7878

7979
return benchmarkFetchCall();
8080
})
8181
);
8282

83-
const average = calls.reduce((time, sum) => sum + time) / calls.length;
83+
const averageMs = callDurationsMs.reduce((time, sum) => sum + time) / callDurationsMs.length;
8484

8585
return {
86-
calls,
87-
average,
86+
callDurationsMs,
87+
averageMs,
8888
};
8989
}
9090

benchmarking/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ console.log(`The benchmarking results have been written in ${outputFile}`);
3232
console.log("\n\nSummary: ");
3333
const summary = benchmarkingResults.map(({ name, fetchBenchmark }) => ({
3434
name,
35-
"average fetch duration (ms)": Math.round(fetchBenchmark.average),
35+
"average fetch duration (ms)": Math.round(fetchBenchmark.averageMs),
3636
}));
3737
console.table(summary);
3838

0 commit comments

Comments
 (0)