summaryrefslogtreecommitdiff
path: root/benchmark/perf_hooks/usertiming.js
blob: 24a53a116785dfb21211730e75fdc24f42fe11fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';

const common = require('../common.js');

const {
  PerformanceObserver,
  performance,
} = require('perf_hooks');

const bench = common.createBenchmark(main, {
  n: [1e5],
  observe: ['all', 'measure'],
});

function test() {
  performance.mark('a');
  performance.mark('b');
  performance.measure('a to b', 'a', 'b');
}

function main({ n, observe }) {
  const entryTypes = observe === 'all' ?
    [ 'mark', 'measure' ] :
    [ observe ];
  const obs = new PerformanceObserver(() => {
    bench.end(n);
  });
  obs.observe({ entryTypes, buffered: true });

  bench.start();
  performance.mark('start');
  for (let i = 0; i < 1e5; i++)
    test();
}