mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
benchmark: add toNamespacedPath bench
PR-URL: https://github.com/nodejs/node/pull/52236 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
511be6cee7
commit
dde0cffb2e
2 changed files with 54 additions and 0 deletions
26
benchmark/path/toNamespacedPath-posix.js
Normal file
26
benchmark/path/toNamespacedPath-posix.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const { posix } = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
path: [
|
||||
'',
|
||||
'.',
|
||||
'/tmp/bar',
|
||||
'/home/node/..',
|
||||
posix.join(__dirname, '/..'),
|
||||
'bar/baz',
|
||||
],
|
||||
n: [1e5],
|
||||
});
|
||||
|
||||
function main({ n, path }) {
|
||||
bench.start();
|
||||
let a;
|
||||
for (let i = 0; i < n; i++) {
|
||||
a = posix.toNamespacedPath(path);
|
||||
}
|
||||
bench.end(n);
|
||||
assert.ok(a + 'a');
|
||||
}
|
28
benchmark/path/toNamespacedPath-win32.js
Normal file
28
benchmark/path/toNamespacedPath-win32.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const { win32 } = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
path: [
|
||||
'',
|
||||
'c:/ignore',
|
||||
'd:\\a/b\\c/d',
|
||||
'\\e.exe',
|
||||
'c:/blah\\blah',
|
||||
'd:/games',
|
||||
'c:../a',
|
||||
win32.join(__dirname, '/..'),
|
||||
],
|
||||
n: [1e5],
|
||||
});
|
||||
|
||||
function main({ n, path }) {
|
||||
bench.start();
|
||||
let a;
|
||||
for (let i = 0; i < n; i++) {
|
||||
a = win32.toNamespacedPath(path);
|
||||
}
|
||||
bench.end(n);
|
||||
assert.ok(a + 'a');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue