Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Add measure function

Compare
Choose a tag to compare
@omrilotan omrilotan released this 06 Oct 11:09
· 38 commits to master since this release
66f3bab

measure

Wrap a function and measure it's execution time in milliseconds into a performance measure entry.

import { measure } from 'page-timing';
await pageTiming.measure(wait, 'my-function');

// Example: Convert entries to a named array
performance.getEntriesByType('measure').reduce(
  (accumulator, {name, duration}) => Object.assign(accumulator, {[name]: duration}),
  {}
);
// {my-function: 53.35999990347773}

// Example: Retrieve a specific entry
const { duration } = performance.getEntriesByType('measure')
  .find(({name}) => name === 'my-function');
// 53.35999990347773