files/en-us/web/api/profiler/index.md
{{APIRef("JS Self-Profiling API")}}{{SeeCompatTable}}
The Profiler interface of the JS Self-Profiling API enables you to create a profile of some part of your web application's execution.
Profiler object, and starts collecting samples.The following code profiles the doWork() operation, and logs the result.
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });
doWork();
const profile = await profiler.stop();
console.log(JSON.stringify(profile));
The following code profiles the time between the script first running and the window's {{domxref("Window.load_event", "load")}} event firing.
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });
window.addEventListener("load", async () => {
const profile = await profiler.stop();
console.log(JSON.stringify(profile));
});
{{Specifications}}
{{Compat}}