Performance

performance.now

Returns a high-resolution timestamp in milliseconds representing the time elapsed since the page started loading

Syntax

JavaScript
performance.now()

Return Value

A DOMHighResTimeStamp (floating-point number of milliseconds)

Examples

Basic Usage
const start = performance.now()
// ... some operation
const end = performance.now()
console.log(`Took ${end - start}ms`)
Practical Example
function measure<T>(fn: () => T): [T, number] {
  const start = performance.now()
  const result = fn()
  const duration = performance.now() - start
  return [result, duration]
}
Advanced Usage
async function benchmark(fn: () => Promise<void>, iterations = 100) {
  const times: number[] = []
  for (let i = 0; i < iterations; i++) {
    const start = performance.now()
    await fn()
    times.push(performance.now() - start)
  }
  const avg = times.reduce((a, b) => a + b, 0) / times.length
  console.log(`Avg: ${avg.toFixed(2)}ms`)
}

Understanding performance.now

The performance.now method in JavaScript returns a high-resolution timestamp in milliseconds representing the time elapsed since the page started loading. 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.now(). When called, it returns a domhighrestimestamp (floating-point number of milliseconds). Understanding when and how to use now() helps you write more expressive, readable code.

Common use cases for performance.now include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like performance-mark, performance-measure, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for performance.now 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.