-
Notifications
You must be signed in to change notification settings - Fork 21
/
latency.ts
37 lines (33 loc) · 1.05 KB
/
latency.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const numberOfRequests = 50; // Number of requests to send
async function measureLatency(url: string, label: string) {
let totalLatency = 0;
for (let i = 0; i < numberOfRequests; i++) {
const startTime = performance.now();
await fetch(url);
const endTime = performance.now();
totalLatency += endTime - startTime;
}
const averageLatency = totalLatency / numberOfRequests;
console.log(
`\x1b[33m[${label}]\x1b[37m Average latency for ${url} (${numberOfRequests} requests) : ${averageLatency} ms`
);
}
Promise.all([
measureLatency(
"https://gh.fredkiss.dev/Fredkiss3/gh-next/issues/58248",
"production"
),
measureLatency(
"https://gh-dev.fredkiss.dev/Fredkiss3/gh-next/issues/58248",
"staging"
)
// measureLatency("http://localhost:3001/Fredkiss3/gh-next/issues", "docker"),
// measureLatency(
// "http://localhost:3000/Fredkiss3/gh-next/issues",
// "docker swarm"
// ),
// measureLatency(
// "http://localhost:3002/Fredkiss3/gh-next/issues",
// "npm run start"
// )
]).catch(console.error);