summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2015-11-10 16:36:50 -0700
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2016-01-06 11:37:15 -0500
commite74242275708c0eb5c430b44235ab4062f973c2c (patch)
treea66826485ccf5dce44a01d76156b7457cd12319f /benchmark
parentb8366e76ddb24f69c7c0c21d942e722cc01f8381 (diff)
downloadnode-new-e74242275708c0eb5c430b44235ab4062f973c2c.tar.gz
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);
+}