-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add toNamespacedPath bench
PR-URL: #52236 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} |