Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Created September 4, 2019 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmendesneto/ed6be58debc611fcd1c0f3289d3a744f to your computer and use it in GitHub Desktop.
Save willmendesneto/ed6be58debc611fcd1c0f3289d3a744f to your computer and use it in GitHub Desktop.
Example of User Timing API usage
const fetchSomeData = async () => {
const measureName = 'fetchSomeData';
const startMark = `[START]: ${measureName}`;
const endMark = `[END]: ${measureName}`;
try {
const url = 'your-url';
// starting the User Timing API marker for this request
performance.mark(startMark);
const data = await fetch(url);
return data;
} catch (error) {
console.error('Oops!', error);
} finally {
// Finishing the markers and sending the results
performance.mark(endMark);
performance.measure(measureName, startMark, endMark);
performance.clearMeasures(measureName);
performance.clearMarks(startMark);
performance.clearMarks(endMark);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment