Last active
October 17, 2025 13:44
-
-
Save pedrobritto/f6b6f4d3dff44844d7ea93ab28369846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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