Skip to content

Commit 6aeea9c

Browse files
authored
Merge pull request #40 from nucliweb/event-processing-time
Check process times
2 parents 8c0904c + ab4c0fc commit 6aeea9c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

SNIPPETS.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ https://github.com/nucliweb/webperf-snippets/assets/1307927/2987a2ca-3eef-4b73-8
5353
- [Inline CSS Info and Size](#inline-css-info-and-size)
5454
- [Get your `<head>` in order](#get-your-head-in-order)
5555
- [e.g. web.dev](#eg-webdev)
56+
- [Event Processing Time](#event-processing-time)
5657
- [Interaction](#interaction)
5758
- [Long Task](#long-task)
5859
- [Layout Shifts](#layout-shifts)
@@ -787,6 +788,52 @@ Use [capo.js](https://github.com/rviscomi/capo.js) the [Rick Viscomi](https://gi
787788
788789
<img width="842" alt="image" src="https://github.com/rviscomi/capo.js/assets/1120896/fe6bb67c-697a-4fdf-aa28-52429239fcf5">
789790
791+
792+
### Event Processing Time
793+
794+
Find the process time it took for events to finish.
795+
796+
```javascript
797+
798+
// list events to calculate processing time
799+
800+
const events = new Map([
801+
["connectTime", { start: "connectStart", end: "connectEnd" }],
802+
["domainLookupTime", { start: "domainLookupStart", end: "domainLookupEnd" }],
803+
[
804+
"DOMContentLoaded",
805+
{ start: "domContentLoadedEventStart", end: "domContentLoadedEventEnd" }
806+
],
807+
808+
["onload", { start: "loadEventStart", end: "loadEventEnd" }]
809+
]);
810+
811+
const observer = new PerformanceObserver((list) => {
812+
const displayTimes = [];
813+
list.getEntries().forEach((entry) => {
814+
console.log(entry);
815+
for (const [key, value] of events) {
816+
const endValue = entry[value.end];
817+
const startValue = entry[value.start];
818+
819+
const eventTime = endValue - startValue;
820+
821+
displayTimes.push({
822+
url: entry.name,
823+
event: key,
824+
processingTime: `${eventTime.toFixed(2)} ms`
825+
});
826+
}
827+
});
828+
829+
console.table(displayTimes);
830+
});
831+
832+
observer.observe({ type: "navigation", buffered: true });
833+
834+
```
835+
836+
790837
## Interaction
791838
792839
### Long Task

0 commit comments

Comments
 (0)