Measure API Response Fetch Time in Javascript

February 11, 2022tip slips

Might be handy to know how long it takes to finish one response during fetching.

Simply use console.time before fetching and console.timeEnd after the fetch function will do the trick.

  • example using async/await:
console.time("Time taken");
const result = await fetchUserInformation();
console.timeEnd("Time taken"); //> Time taken: 2908ms - timer ended
  • example using promise:
console.time("Time taken");
const result = fetchUserInformation().then(data => {
    console.timeEnd("Time taken"); //> Time taken: 2908ms - timer ended
    return data;
});

See you!