diff options
author | Trevor Norris <trev.norris@gmail.com> | 2016-07-14 11:57:26 -0600 |
---|---|---|
committer | Bartosz Sosnowski <bartosz@janeasystems.com> | 2016-08-12 13:11:01 +0200 |
commit | b9832eb3fe61fcbfb6031e3dfce5eff8567a479c (patch) | |
tree | e2a7525d0185c8d01bd9bcb1bf6bef52fdeb44c3 /benchmark | |
parent | 08996fde3c08c0cfabc7cc3fe332d83f674ab099 (diff) | |
download | android-node-v8-b9832eb3fe61fcbfb6031e3dfce5eff8567a479c.tar.gz android-node-v8-b9832eb3fe61fcbfb6031e3dfce5eff8567a479c.tar.bz2 android-node-v8-b9832eb3fe61fcbfb6031e3dfce5eff8567a479c.zip |
bench: add bench for fs.realpath() fix
The 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.
PR-URL: https://github.com/nodejs/node/pull/7899
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/fs/bench-realpath.js | 46 | ||||
-rw-r--r-- | benchmark/fs/bench-realpathSync.js | 39 |
2 files changed, 85 insertions, 0 deletions
diff --git a/benchmark/fs/bench-realpath.js b/benchmark/fs/bench-realpath.js new file mode 100644 index 0000000000..1a181935f1 --- /dev/null +++ b/benchmark/fs/bench-realpath.js @@ -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)); +} diff --git a/benchmark/fs/bench-realpathSync.js b/benchmark/fs/bench-realpathSync.js new file mode 100644 index 0000000000..ae1c78d30d --- /dev/null +++ b/benchmark/fs/bench-realpathSync.js @@ -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); + } +} |