11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst { posix } = require('path'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci paths: [ 71cb0ef41Sopenharmony_ci ['/data/orandea/test/aaa', '/data/orandea/impl/bbb'].join('|'), 81cb0ef41Sopenharmony_ci ['/', '/var'].join('|'), 91cb0ef41Sopenharmony_ci ['/', '/'].join('|'), 101cb0ef41Sopenharmony_ci ['/var', '/bin'].join('|'), 111cb0ef41Sopenharmony_ci ['/foo/bar/baz/quux', '/'].join('|'), 121cb0ef41Sopenharmony_ci ['/foo/bar/baz/quux', '/foo/bar/baz/quux'].join('|'), 131cb0ef41Sopenharmony_ci ['/foo/bar/baz/quux', '/var/log'].join('|'), 141cb0ef41Sopenharmony_ci ], 151cb0ef41Sopenharmony_ci n: [1e5], 161cb0ef41Sopenharmony_ci}); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction main({ n, paths }) { 191cb0ef41Sopenharmony_ci let to = ''; 201cb0ef41Sopenharmony_ci const delimIdx = paths.indexOf('|'); 211cb0ef41Sopenharmony_ci if (delimIdx > -1) { 221cb0ef41Sopenharmony_ci to = paths.slice(delimIdx + 1); 231cb0ef41Sopenharmony_ci paths = paths.slice(0, delimIdx); 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci bench.start(); 271cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 281cb0ef41Sopenharmony_ci if (i % 3 === 0) 291cb0ef41Sopenharmony_ci posix.relative(`${paths}${i}`, `${to}${i}`); 301cb0ef41Sopenharmony_ci else 311cb0ef41Sopenharmony_ci posix.relative(paths, to); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci bench.end(n); 341cb0ef41Sopenharmony_ci} 35