Created
March 14, 2025 14:03
-
-
Save Git-I985/b529ff1c946bec7e4ba04381ef39d924 to your computer and use it in GitHub Desktop.
Avg response time measurement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getResponseTime() { | |
const start = performance.now() | |
await fetch('YOUR_URL_HERE') | |
return performance.now()-start | |
} | |
async function main() { | |
const times = [] | |
for (let i = 0; i < 100; i++) { | |
console.clear() | |
console.log(`Call api ${i}`); | |
await new Promise((res) => { | |
setTimeout(res, 500) | |
}) | |
times.push(await getResponseTime()) | |
} | |
console.table(times); | |
console.log("Среднее время ответа ~", times.reduce((acc, time) => acc + time, 0)/times.length, 'ms'); | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment