11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst fs = require('fs');
51cb0ef41Sopenharmony_ciconst path = require('path');
61cb0ef41Sopenharmony_ciconst resolved_path = path.resolve(__dirname, '../../lib/');
71cb0ef41Sopenharmony_ciconst relative_path = path.relative(__dirname, '../../lib/');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
101cb0ef41Sopenharmony_ci  n: [1e4],
111cb0ef41Sopenharmony_ci  pathType: ['relative', 'resolved'],
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction main({ n, pathType }) {
161cb0ef41Sopenharmony_ci  bench.start();
171cb0ef41Sopenharmony_ci  if (pathType === 'relative')
181cb0ef41Sopenharmony_ci    relativePath(n);
191cb0ef41Sopenharmony_ci  else
201cb0ef41Sopenharmony_ci    resolvedPath(n);
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cifunction relativePath(n) {
241cb0ef41Sopenharmony_ci  (function r(cntr) {
251cb0ef41Sopenharmony_ci    if (cntr-- <= 0)
261cb0ef41Sopenharmony_ci      return bench.end(n);
271cb0ef41Sopenharmony_ci    fs.realpath(relative_path, () => {
281cb0ef41Sopenharmony_ci      r(cntr);
291cb0ef41Sopenharmony_ci    });
301cb0ef41Sopenharmony_ci  }(n));
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cifunction resolvedPath(n) {
341cb0ef41Sopenharmony_ci  (function r(cntr) {
351cb0ef41Sopenharmony_ci    if (cntr-- <= 0)
361cb0ef41Sopenharmony_ci      return bench.end(n);
371cb0ef41Sopenharmony_ci    fs.realpath(resolved_path, () => {
381cb0ef41Sopenharmony_ci      r(cntr);
391cb0ef41Sopenharmony_ci    });
401cb0ef41Sopenharmony_ci  }(n));
411cb0ef41Sopenharmony_ci}
42