1'use strict'; 2const common = require('../common.js'); 3const { posix } = require('path'); 4 5const bench = common.createBenchmark(main, { 6 paths: [ 7 '', 8 ['', ''].join('|'), 9 ['foo/bar', '/tmp/file/', '..', 'a/../subfile'].join('|'), 10 ['a/b/c/', '../../..'].join('|'), 11 ], 12 n: [1e5] 13}); 14 15function main({ n, paths }) { 16 const args = paths.split('|'); 17 const copy = [...args]; 18 const orig = copy[0]; 19 20 bench.start(); 21 for (let i = 0; i < n; i++) { 22 if (i % 3 === 0) { 23 copy[0] = `${orig}${i}`; 24 posix.resolve(...copy); 25 } else { 26 posix.resolve(...args); 27 } 28 } 29 bench.end(n); 30} 31