summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2015-11-10 16:36:50 -0700
committerTrevor Norris <trev.norris@gmail.com>2015-12-17 17:29:06 -0700
commit0fde28ce37c3b70dcf61611c7d42bf9a586fe234 (patch)
tree8c2fa222b4b4ecda143525fbe3103d8ca6765e8f /benchmark
parentd39ace16bacd57cce2fa2063fe0b5503c544e743 (diff)
downloadandroid-node-v8-0fde28ce37c3b70dcf61611c7d42bf9a586fe234.tar.gz
android-node-v8-0fde28ce37c3b70dcf61611c7d42bf9a586fe234.tar.bz2
android-node-v8-0fde28ce37c3b70dcf61611c7d42bf9a586fe234.zip
fs: use pushValueToArray for readdir(Sync)
Improve performance by pushing directory entries to returned array in batches of 8 using pushValueToArray() in JS. Add benchmarks to demonstrate this improvement. PR-URL: https://github.com/nodejs/node/pull/3780 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/fs/bench-readdir.js22
-rw-r--r--benchmark/fs/bench-readdirSync.js19
2 files changed, 41 insertions, 0 deletions
diff --git a/benchmark/fs/bench-readdir.js b/benchmark/fs/bench-readdir.js
new file mode 100644
index 0000000000..2f0eab6a82
--- /dev/null
+++ b/benchmark/fs/bench-readdir.js
@@ -0,0 +1,22 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ n: [1e4],
+});
+
+
+function main(conf) {
+ const n = conf.n >>> 0;
+
+ bench.start();
+ (function r(cntr) {
+ if (--cntr <= 0)
+ return bench.end(n);
+ fs.readdir(__dirname + '/../../lib/', function() {
+ r(cntr);
+ });
+ }(n));
+}
diff --git a/benchmark/fs/bench-readdirSync.js b/benchmark/fs/bench-readdirSync.js
new file mode 100644
index 0000000000..9f89649138
--- /dev/null
+++ b/benchmark/fs/bench-readdirSync.js
@@ -0,0 +1,19 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ n: [1e4],
+});
+
+
+function main(conf) {
+ const n = conf.n >>> 0;
+
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ fs.readdirSync(__dirname + '/../../lib/');
+ }
+ bench.end(n);
+}