Skip to content

Instantly share code, notes, and snippets.

@Git-I985
Created March 14, 2025 14:03
Show Gist options
  • Save Git-I985/b529ff1c946bec7e4ba04381ef39d924 to your computer and use it in GitHub Desktop.
Save Git-I985/b529ff1c946bec7e4ba04381ef39d924 to your computer and use it in GitHub Desktop.
Avg response time measurement
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