performance.measure
Creates a named PerformanceMeasure entry representing the time between two marks in the performance timeline
Syntax
performance.measure(name, startMark?, endMark?)Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the measure |
| startMark | string | PerformanceMeasureOptions | The start mark name or options object |
| endMark | string | The end mark name |
Return Value
A PerformanceMeasure object with a duration property
Examples
performance.mark('start')
// ... operation
performance.mark('end')
const entry = performance.measure('operation', 'start', 'end')
console.log(`Duration: ${entry.duration}ms`)performance.mark('api-start')
await fetch('/api/users')
performance.mark('api-end')
const m = performance.measure('api-call', 'api-start', 'api-end')
console.log(`API call: ${m.duration.toFixed(2)}ms`)const entries = performance.getEntriesByType('measure')
entries.forEach(entry => {
console.log(`${entry.name}: ${entry.duration.toFixed(2)}ms`)
})Understanding performance.measure
The performance.measure method in JavaScript creates a named PerformanceMeasure entry representing the time between two marks in the performance timeline. It belongs to the Performance object and is one of the most widely used methods for working with performance values in modern JavaScript and TypeScript applications.
The method signature is performance.measure(name, startMark?, endMark?). It accepts 3 parameters: name, startMark, endMark. When called, it returns a performancemeasure object with a duration property. Understanding when and how to use measure() helps you write more expressive, readable code.
Common use cases for performance.measure include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like performance-mark, performance-now, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for performance.measure is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Performance Methods
Other methods in the Performance object
Related Tools
More Performance Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.