xref: /third_party/node/benchmark/perf_hooks/usertiming.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/benchmark/perf_hooks/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common.js');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst {
61cb0ef41Sopenharmony_ci  PerformanceObserver,
71cb0ef41Sopenharmony_ci  performance,
81cb0ef41Sopenharmony_ci} = require('perf_hooks');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
111cb0ef41Sopenharmony_ci  n: [1e5],
121cb0ef41Sopenharmony_ci  observe: ['all', 'measure'],
131cb0ef41Sopenharmony_ci});
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction test() {
161cb0ef41Sopenharmony_ci  performance.mark('a');
171cb0ef41Sopenharmony_ci  performance.mark('b');
181cb0ef41Sopenharmony_ci  performance.measure('a to b', 'a', 'b');
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cifunction main({ n, observe }) {
221cb0ef41Sopenharmony_ci  const entryTypes = observe === 'all' ?
231cb0ef41Sopenharmony_ci    [ 'mark', 'measure' ] :
241cb0ef41Sopenharmony_ci    [ observe ];
251cb0ef41Sopenharmony_ci  const obs = new PerformanceObserver(() => {
261cb0ef41Sopenharmony_ci    bench.end(n);
271cb0ef41Sopenharmony_ci  });
281cb0ef41Sopenharmony_ci  obs.observe({ entryTypes, buffered: true });
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  bench.start();
311cb0ef41Sopenharmony_ci  performance.mark('start');
321cb0ef41Sopenharmony_ci  for (let i = 0; i < 1e5; i++)
331cb0ef41Sopenharmony_ci    test();
341cb0ef41Sopenharmony_ci}
35

Indexes created Thu Nov 07 10:32:03 CST 2024