• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4
5const {
6  PerformanceObserver,
7  performance,
8} = require('perf_hooks');
9
10const bench = common.createBenchmark(main, {
11  n: [1e5],
12  observe: ['all', 'measure'],
13});
14
15function test() {
16  performance.mark('a');
17  performance.mark('b');
18  performance.measure('a to b', 'a', 'b');
19}
20
21function main({ n, observe }) {
22  const entryTypes = observe === 'all' ?
23    [ 'mark', 'measure' ] :
24    [ observe ];
25  const obs = new PerformanceObserver(() => {
26    bench.end(n);
27  });
28  obs.observe({ entryTypes, buffered: true });
29
30  bench.start();
31  performance.mark('start');
32  for (let i = 0; i < 1e5; i++)
33    test();
34}
35