xref: /third_party/node/benchmark/napi/ref/index.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/benchmark/napi/ref/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../../common');
31cb0ef41Sopenharmony_ciconst addon = require(`./build/${common.buildType}/addon`);
41cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { n: [1e7] });
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cifunction callNewWeak() {
71cb0ef41Sopenharmony_ci  addon.newWeak();
81cb0ef41Sopenharmony_ci}
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction main({ n }) {
111cb0ef41Sopenharmony_ci  addon.count = 0;
121cb0ef41Sopenharmony_ci  bench.start();
131cb0ef41Sopenharmony_ci  new Promise((resolve) => {
141cb0ef41Sopenharmony_ci    (function oneIteration() {
151cb0ef41Sopenharmony_ci      callNewWeak();
161cb0ef41Sopenharmony_ci      setImmediate(() => ((addon.count < n) ? oneIteration() : resolve()));
171cb0ef41Sopenharmony_ci    })();
181cb0ef41Sopenharmony_ci  }).then(() => bench.end(n));
191cb0ef41Sopenharmony_ci}
20

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