xref: /third_party/node/benchmark/dns/lookup-promises.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/benchmark/dns/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common.js');
41cb0ef41Sopenharmony_ciconst { lookup } = require('dns').promises;
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
71cb0ef41Sopenharmony_ci  name: ['127.0.0.1', '::1'],
81cb0ef41Sopenharmony_ci  all: ['true', 'false'],
91cb0ef41Sopenharmony_ci  n: [5e6],
101cb0ef41Sopenharmony_ci});
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction main({ name, n, all }) {
131cb0ef41Sopenharmony_ci  if (all === 'true') {
141cb0ef41Sopenharmony_ci    const opts = { all: true };
151cb0ef41Sopenharmony_ci    bench.start();
161cb0ef41Sopenharmony_ci    (async function cb() {
171cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i++) {
181cb0ef41Sopenharmony_ci        await lookup(name, opts);
191cb0ef41Sopenharmony_ci      }
201cb0ef41Sopenharmony_ci    })();
211cb0ef41Sopenharmony_ci    bench.end(n);
221cb0ef41Sopenharmony_ci  } else {
231cb0ef41Sopenharmony_ci    bench.start();
241cb0ef41Sopenharmony_ci    (async function cb() {
251cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i++) {
261cb0ef41Sopenharmony_ci        await lookup(name);
271cb0ef41Sopenharmony_ci      }
281cb0ef41Sopenharmony_ci    })();
291cb0ef41Sopenharmony_ci    bench.end(n);
301cb0ef41Sopenharmony_ci  }
311cb0ef41Sopenharmony_ci}
32

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