Course contentsShow
← Web Development
Lesson 1920 of 2,98235. Web Performance FundamentalsFree lesson

User Timing API

Create custom performance marks and measures to track specific application events.

User Timing API

What you'll learn: How to create custom performance marks and measures to track specific application events beyond the browser's default metrics.

What Is the User Timing API?

The User Timing API lets you create your own performance checkpoints ("marks") and calculate time intervals ("measures") between them. While the Performance API gives you built-in browser metrics, the User Timing API empowers you to instrument your own application logic—like tracking how long a user checkout flow takes or when a specific component finished rendering.

Think of it like placing custom mile markers on a race course. The browser already tracks standard checkpoints (start line, finish line), but you might want to know exactly when runners pass your custom landmarks: "Through the tunnel!" or "Past the water station!"

Creating Marks

Use performance.mark() to record a timestamp at a specific moment:

// Mark the start of a critical operation
performance.mark('checkout-start');

// ... user fills out checkout form ...

// Mark when checkout completes
performance.mark('checkout-complete');

Creating Measures

Use performance.measure() to calculate the duration between two marks:

// Measure time between marks
performance.measure('checkout-duration', 'checkout-start', 'checkout-complete');

// Retrieve the measurement
const measures = performance.getEntriesByName('checkout-duration');
console.log(`Checkout took ${measures[0].duration}ms`);

You can also measure from built-in navigation timing points:

performance.measure('time-to-interactive', 'navigationStart', 'custom-interactive-mark');

Why This Matters

Custom marks and measures help you understand the performance of business-critical features that standard metrics miss. You can track feature-specific bottlenecks, analyze user journey timings, and make data-driven optimization decisions about what matters most to your application.

Key Takeaway: The User Timing API extends browser performance measurement with custom marks and measures, letting you track application-specific events and calculate meaningful durations for your unique user flows.