-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test,bench: add tests/bench for fs.realpath() fix
The test/benchmarks included also work for the previous JS implementation of fs.realpath(). In case the new implementation of realpath() needs to be reverted, we want these changes to stick around.
- Loading branch information
1 parent
bf8827b
commit e7a38ab
Showing
3 changed files
with
158 additions
and
2 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,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const resolved_path = path.resolve(__dirname, '../../lib/'); | ||
const relative_path = path.relative(__dirname, '../../lib/'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e4], | ||
type: ['relative', 'resolved'], | ||
}); | ||
|
||
|
||
function main(conf) { | ||
const n = conf.n >>> 0; | ||
const type = conf.type; | ||
|
||
bench.start(); | ||
if (type === 'relative') | ||
relativePath(n); | ||
else if (type === 'resolved') | ||
resolvedPath(n); | ||
else | ||
throw new Error('unknown "type": ' + type); | ||
} | ||
|
||
function relativePath(n) { | ||
(function r(cntr) { | ||
if (--cntr <= 0) | ||
return bench.end(n); | ||
fs.realpath(relative_path, function() { | ||
r(cntr); | ||
}); | ||
}(n)); | ||
} | ||
|
||
function resolvedPath(n) { | ||
(function r(cntr) { | ||
if (--cntr <= 0) | ||
return bench.end(n); | ||
fs.realpath(resolved_path, function() { | ||
r(cntr); | ||
}); | ||
}(n)); | ||
} |
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,39 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const resolved_path = path.resolve(__dirname, '../../lib/'); | ||
const relative_path = path.relative(__dirname, '../../lib/'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e4], | ||
type: ['relative', 'resolved'], | ||
}); | ||
|
||
|
||
function main(conf) { | ||
const n = conf.n >>> 0; | ||
const type = conf.type; | ||
|
||
bench.start(); | ||
if (type === 'relative') | ||
relativePath(n); | ||
else if (type === 'resolved') | ||
resolvedPath(n); | ||
else | ||
throw new Error('unknown "type": ' + type); | ||
bench.end(n); | ||
} | ||
|
||
function relativePath(n) { | ||
for (var i = 0; i < n; i++) { | ||
fs.realpathSync(relative_path); | ||
} | ||
} | ||
|
||
function resolvedPath(n) { | ||
for (var i = 0; i < n; i++) { | ||
fs.realpathSync(resolved_path); | ||
} | ||
} |
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