Skip to content

Instantly share code, notes, and snippets.

@pedrobritto
Last active October 17, 2025 13:44
Show Gist options
  • Select an option

  • Save pedrobritto/f6b6f4d3dff44844d7ea93ab28369846 to your computer and use it in GitHub Desktop.

Select an option

Save pedrobritto/f6b6f4d3dff44844d7ea93ab28369846 to your computer and use it in GitHub Desktop.
function performanceMarks() {
const marks: object[] = [];
function mark(label: string) {
marks.push({ label: label, timestamp: performance.now() });
}
function getSummary() {
if (marks.length < 2) {
console.warn('You need at least two marks to generate a summary.');
return;
}
const formatted = [];
marks.forEach((_, index, arr) => {
if (index > 0) {
formatted.push({
label: `${arr[index - 1].label} -> ${arr[index].label}`,
ellapsed_time: arr[index].timestamp - arr[index - 1].timestamp,
});
}
});
marks.pop();
console.table(formatted);
}
return {
mark,
getSummary,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment