Skip to content

Instantly share code, notes, and snippets.

@matfin
Last active November 14, 2020 13:30
Show Gist options
  • Select an option

  • Save matfin/08a11b774b7e3ec737bb970767d04179 to your computer and use it in GitHub Desktop.

Select an option

Save matfin/08a11b774b7e3ec737bb970767d04179 to your computer and use it in GitHub Desktop.
const hammerTime = async (url, numCalls) => {
const start = performance.now();
const results = [];
for(let i = 0; i < numCalls; i++) {
const res = await fetch(url);
const data = await res.text();
results.push(data);
}
const end = performance.now();
return `${numCalls} calls to ${url} took: ${end - start}ms`;
};
// send through 20 calls every second
setInterval(async () => {
let result = await hammerTime('https://mattfinucane.com', 20);
console.log(result);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment