The Performance API measures how long operations take:
performance.mark("start");
// ... do work ...
performance.mark("end");
performance.measure("work", "start", "end");
const measure = performance.getEntriesByName("work")[0];
console.log(measure.duration); // milliseconds
Use this to find and fix performance bottlenecks.