@@ -3,8 +3,8 @@ import nodeFsPromises from "node:fs/promises";
33import nodePath from "node:path" ;
44
55export type FetchBenchmark = {
6- calls : number [ ] ;
7- average : number ;
6+ callDurationsMs : number [ ] ;
7+ averageMs : number ;
88} ;
99
1010export type BenchmarkingResults = {
@@ -40,13 +40,13 @@ export async function benchmarkApplicationResponseTime({
4040
4141type BenchmarkFetchOptions = {
4242 numberOfCalls ?: number ;
43- randomDelayMax ?: number ;
43+ maxRandomDelayMs ?: number ;
4444 fetch : ( deploymentUrl : string ) => Promise < Response > ;
4545} ;
4646
4747const 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 */
5959async 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
0 commit comments