-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestResponseTime.js
47 lines (43 loc) · 1.47 KB
/
testResponseTime.js
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
38
39
40
41
42
43
44
45
46
47
var https = require("https");
// Define the URL and the number of requests
// var url = "d2jjvnhym149vv.cloudfront.net";
var url = "next-app-dir-seven.vercel.app";
var requests = 100;
// Create an array to store the response times
var times = [];
// Define a function to make a request and measure the time
function makeRequest() {
// Get the current time before sending the request
var startTime = Date.now();
// Send an HTTP HEAD request to get only the headers
var req = https.request(
{ hostname: url, path: `/isr`, method: "GET" },
function (res) {
// Get the current time after receiving the response
var endTime = Date.now();
// Calculate the response time in milliseconds
var responseTime = endTime - startTime;
console.log(
`Response time for request ${times.length + 1}: ${responseTime} ms`
);
// Push the response time to the array
times.push(responseTime);
// Check if there are more requests to make
if (times.length < requests) {
// Wait for 500 milliseconds before making another request
setTimeout(makeRequest, 500);
} else {
// Compute the average response time
var sum = times.reduce(function (a, b) {
return a + b;
});
var average = sum / times.length;
// Display the average response time
console.log("Average response time: " + average + " ms");
}
}
);
req.end();
}
// Start making requests
makeRequest();