xref: /third_party/node/test/parallel/test-performance-measure.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst { PerformanceObserver, performance } = require('perf_hooks');
71cb0ef41Sopenharmony_ciconst DELAY = 1000;
81cb0ef41Sopenharmony_ciconst ALLOWED_MARGIN = 10;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst expected = ['Start to Now', 'A to Now', 'A to B'];
111cb0ef41Sopenharmony_ciconst obs = new PerformanceObserver(common.mustCall((items) => {
121cb0ef41Sopenharmony_ci  items.getEntries().forEach(({ name, duration }) => {
131cb0ef41Sopenharmony_ci    assert.ok(duration > (DELAY - ALLOWED_MARGIN));
141cb0ef41Sopenharmony_ci    assert.strictEqual(expected.shift(), name);
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci}));
171cb0ef41Sopenharmony_ciobs.observe({ entryTypes: ['measure'] });
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciperformance.mark('A');
201cb0ef41Sopenharmony_cisetTimeout(common.mustCall(() => {
211cb0ef41Sopenharmony_ci  performance.measure('Start to Now');
221cb0ef41Sopenharmony_ci  performance.measure('A to Now', 'A');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  performance.mark('B');
251cb0ef41Sopenharmony_ci  performance.measure('A to B', 'A', 'B');
261cb0ef41Sopenharmony_ci}), DELAY);
27

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