• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
6const { PerformanceObserver, performance } = require('perf_hooks');
7const DELAY = 1000;
8
9const expected = ['Start to Now', 'A to Now', 'A to B'];
10const obs = new PerformanceObserver(common.mustCall((items) => {
11  const entries = items.getEntries();
12  const { name, duration } = entries[0];
13  assert.ok(duration > DELAY);
14  assert.strictEqual(expected.shift(), name);
15}, 3));
16obs.observe({ entryTypes: ['measure'] });
17
18performance.mark('A');
19setTimeout(common.mustCall(() => {
20  performance.measure('Start to Now');
21  performance.measure('A to Now', 'A');
22
23  performance.mark('B');
24  performance.measure('A to B', 'A', 'B');
25}), DELAY);
26