summaryrefslogtreecommitdiff
path: root/deps/node/benchmark/fs
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-04-03 15:43:32 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-04-03 15:45:57 +0200
commit71e285b94c7edaa43aa8115965cf5a36b8e0f80a (patch)
tree7d4aa9d0d5aff686b106cd5da72ba77960c4af43 /deps/node/benchmark/fs
parent7dadf9356b4f3f4137ce982ea5bb960283116e9a (diff)
downloadakono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.gz
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.bz2
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.zip
Node.js v11.13.0
Diffstat (limited to 'deps/node/benchmark/fs')
-rw-r--r--deps/node/benchmark/fs/bench-mkdirp.js23
-rw-r--r--deps/node/benchmark/fs/bench-readdir.js24
-rw-r--r--deps/node/benchmark/fs/bench-readdirSync.js22
-rw-r--r--deps/node/benchmark/fs/bench-realpath.js41
-rw-r--r--deps/node/benchmark/fs/bench-realpathSync.js24
-rw-r--r--deps/node/benchmark/fs/bench-stat-promise.js28
-rw-r--r--deps/node/benchmark/fs/bench-stat.js31
-rw-r--r--deps/node/benchmark/fs/bench-statSync.js26
-rw-r--r--deps/node/benchmark/fs/read-stream-throughput.js90
-rw-r--r--deps/node/benchmark/fs/readFileSync.js15
-rw-r--r--deps/node/benchmark/fs/readfile-partitioned.js86
-rw-r--r--deps/node/benchmark/fs/readfile.js58
-rw-r--r--deps/node/benchmark/fs/write-stream-throughput.js69
13 files changed, 537 insertions, 0 deletions
diff --git a/deps/node/benchmark/fs/bench-mkdirp.js b/deps/node/benchmark/fs/bench-mkdirp.js
new file mode 100644
index 00000000..b9e62045
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-mkdirp.js
@@ -0,0 +1,23 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+const tmpdir = require('../../test/common/tmpdir');
+tmpdir.refresh();
+let dirc = 0;
+
+const bench = common.createBenchmark(main, {
+ n: [1e4],
+});
+
+function main({ n }) {
+ bench.start();
+ (function r(cntr) {
+ if (cntr-- <= 0)
+ return bench.end(n);
+ const pathname = `${tmpdir.path}/${++dirc}/${++dirc}/${++dirc}/${++dirc}`;
+ fs.mkdir(pathname, { recursive: true }, (err) => {
+ r(cntr);
+ });
+ }(n));
+}
diff --git a/deps/node/benchmark/fs/bench-readdir.js b/deps/node/benchmark/fs/bench-readdir.js
new file mode 100644
index 00000000..3731e35a
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-readdir.js
@@ -0,0 +1,24 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+const path = require('path');
+
+const bench = common.createBenchmark(main, {
+ n: [10],
+ dir: [ 'lib', 'test/parallel'],
+ withFileTypes: ['true', 'false']
+});
+
+function main({ n, dir, withFileTypes }) {
+ withFileTypes = withFileTypes === 'true';
+ const fullPath = path.resolve(__dirname, '../../', dir);
+ bench.start();
+ (function r(cntr) {
+ if (cntr-- <= 0)
+ return bench.end(n);
+ fs.readdir(fullPath, { withFileTypes }, () => {
+ r(cntr);
+ });
+ }(n));
+}
diff --git a/deps/node/benchmark/fs/bench-readdirSync.js b/deps/node/benchmark/fs/bench-readdirSync.js
new file mode 100644
index 00000000..5d0e9739
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-readdirSync.js
@@ -0,0 +1,22 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+const path = require('path');
+
+const bench = common.createBenchmark(main, {
+ n: [10],
+ dir: [ 'lib', 'test/parallel'],
+ withFileTypes: ['true', 'false']
+});
+
+
+function main({ n, dir, withFileTypes }) {
+ withFileTypes = withFileTypes === 'true';
+ const fullPath = path.resolve(__dirname, '../../', dir);
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ fs.readdirSync(fullPath, { withFileTypes });
+ }
+ bench.end(n);
+}
diff --git a/deps/node/benchmark/fs/bench-realpath.js b/deps/node/benchmark/fs/bench-realpath.js
new file mode 100644
index 00000000..97148437
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-realpath.js
@@ -0,0 +1,41 @@
+'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],
+ pathType: ['relative', 'resolved'],
+});
+
+
+function main({ n, pathType }) {
+ bench.start();
+ if (pathType === 'relative')
+ relativePath(n);
+ else
+ resolvedPath(n);
+}
+
+function relativePath(n) {
+ (function r(cntr) {
+ if (cntr-- <= 0)
+ return bench.end(n);
+ fs.realpath(relative_path, () => {
+ r(cntr);
+ });
+ }(n));
+}
+
+function resolvedPath(n) {
+ (function r(cntr) {
+ if (cntr-- <= 0)
+ return bench.end(n);
+ fs.realpath(resolved_path, () => {
+ r(cntr);
+ });
+ }(n));
+}
diff --git a/deps/node/benchmark/fs/bench-realpathSync.js b/deps/node/benchmark/fs/bench-realpathSync.js
new file mode 100644
index 00000000..7a01bd18
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-realpathSync.js
@@ -0,0 +1,24 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+const path = require('path');
+
+process.chdir(__dirname);
+const resolved_path = path.resolve(__dirname, '../../lib/');
+const relative_path = path.relative(__dirname, '../../lib/');
+
+const bench = common.createBenchmark(main, {
+ n: [1e4],
+ pathType: ['relative', 'resolved'],
+});
+
+
+function main({ n, pathType }) {
+ const path = pathType === 'relative' ? relative_path : resolved_path;
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ fs.realpathSync(path);
+ }
+ bench.end(n);
+}
diff --git a/deps/node/benchmark/fs/bench-stat-promise.js b/deps/node/benchmark/fs/bench-stat-promise.js
new file mode 100644
index 00000000..99a5da57
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-stat-promise.js
@@ -0,0 +1,28 @@
+'use strict';
+
+const common = require('../common');
+const fsPromises = require('fs').promises;
+
+const bench = common.createBenchmark(main, {
+ n: [20e4],
+ statType: ['fstat', 'lstat', 'stat']
+});
+
+async function run(n, statType) {
+ const handleMode = statType === 'fstat';
+ const arg = handleMode ? await fsPromises.open(__filename, 'r') : __filename;
+ let remaining = n;
+ bench.start();
+ while (remaining-- > 0)
+ await (handleMode ? arg.stat() : fsPromises[statType](arg));
+ bench.end(n);
+
+ if (typeof arg.close === 'function')
+ await arg.close();
+}
+
+function main(conf) {
+ const n = conf.n >>> 0;
+ const statType = conf.statType;
+ run(n, statType).catch(console.log);
+}
diff --git a/deps/node/benchmark/fs/bench-stat.js b/deps/node/benchmark/fs/bench-stat.js
new file mode 100644
index 00000000..0b2e1972
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-stat.js
@@ -0,0 +1,31 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ n: [20e4],
+ statType: ['fstat', 'lstat', 'stat']
+});
+
+
+function main({ n, statType }) {
+ var arg;
+ if (statType === 'fstat')
+ arg = fs.openSync(__filename, 'r');
+ else
+ arg = __filename;
+
+ bench.start();
+ (function r(cntr, fn) {
+ if (cntr-- <= 0) {
+ bench.end(n);
+ if (statType === 'fstat')
+ fs.closeSync(arg);
+ return;
+ }
+ fn(arg, () => {
+ r(cntr, fn);
+ });
+ }(n, fs[statType]));
+}
diff --git a/deps/node/benchmark/fs/bench-statSync.js b/deps/node/benchmark/fs/bench-statSync.js
new file mode 100644
index 00000000..bd8754a6
--- /dev/null
+++ b/deps/node/benchmark/fs/bench-statSync.js
@@ -0,0 +1,26 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ n: [1e6],
+ statSyncType: ['fstatSync', 'lstatSync', 'statSync']
+});
+
+
+function main({ n, statSyncType }) {
+ const arg = (statSyncType === 'fstatSync' ?
+ fs.openSync(__filename, 'r') :
+ __dirname);
+ const fn = fs[statSyncType];
+
+ bench.start();
+ for (var i = 0; i < n; i++) {
+ fn(arg);
+ }
+ bench.end(n);
+
+ if (statSyncType === 'fstat')
+ fs.closeSync(arg);
+}
diff --git a/deps/node/benchmark/fs/read-stream-throughput.js b/deps/node/benchmark/fs/read-stream-throughput.js
new file mode 100644
index 00000000..cb5d98dc
--- /dev/null
+++ b/deps/node/benchmark/fs/read-stream-throughput.js
@@ -0,0 +1,90 @@
+// Test the throughput of the fs.WriteStream class.
+'use strict';
+
+const path = require('path');
+const common = require('../common.js');
+const filename = path.resolve(process.env.NODE_TMPDIR || __dirname,
+ `.removeme-benchmark-garbage-${process.pid}`);
+const fs = require('fs');
+const assert = require('assert');
+
+let encodingType, encoding, size, filesize;
+
+const bench = common.createBenchmark(main, {
+ encodingType: ['buf', 'asc', 'utf'],
+ filesize: [1000 * 1024 * 1024],
+ size: [1024, 4096, 65535, 1024 * 1024]
+});
+
+function main(conf) {
+ encodingType = conf.encodingType;
+ size = conf.size;
+ filesize = conf.filesize;
+
+ switch (encodingType) {
+ case 'buf':
+ encoding = null;
+ break;
+ case 'asc':
+ encoding = 'ascii';
+ break;
+ case 'utf':
+ encoding = 'utf8';
+ break;
+ default:
+ throw new Error(`invalid encodingType: ${encodingType}`);
+ }
+
+ makeFile();
+}
+
+function runTest() {
+ assert(fs.statSync(filename).size === filesize);
+ const rs = fs.createReadStream(filename, {
+ highWaterMark: size,
+ encoding: encoding
+ });
+
+ rs.on('open', () => {
+ bench.start();
+ });
+
+ var bytes = 0;
+ rs.on('data', (chunk) => {
+ bytes += chunk.length;
+ });
+
+ rs.on('end', () => {
+ try { fs.unlinkSync(filename); } catch {}
+ // MB/sec
+ bench.end(bytes / (1024 * 1024));
+ });
+}
+
+function makeFile() {
+ const buf = Buffer.allocUnsafe(filesize / 1024);
+ if (encoding === 'utf8') {
+ // ü
+ for (var i = 0; i < buf.length; i++) {
+ buf[i] = i % 2 === 0 ? 0xC3 : 0xBC;
+ }
+ } else if (encoding === 'ascii') {
+ buf.fill('a');
+ } else {
+ buf.fill('x');
+ }
+
+ try { fs.unlinkSync(filename); } catch {}
+ var w = 1024;
+ const ws = fs.createWriteStream(filename);
+ ws.on('close', runTest);
+ ws.on('drain', write);
+ write();
+ function write() {
+ do {
+ w--;
+ } while (false !== ws.write(buf) && w > 0);
+ if (w === 0)
+ ws.end();
+ }
+}
diff --git a/deps/node/benchmark/fs/readFileSync.js b/deps/node/benchmark/fs/readFileSync.js
new file mode 100644
index 00000000..c28adeb2
--- /dev/null
+++ b/deps/node/benchmark/fs/readFileSync.js
@@ -0,0 +1,15 @@
+'use strict';
+
+const common = require('../common.js');
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ n: [60e4]
+});
+
+function main({ n }) {
+ bench.start();
+ for (var i = 0; i < n; ++i)
+ fs.readFileSync(__filename);
+ bench.end(n);
+}
diff --git a/deps/node/benchmark/fs/readfile-partitioned.js b/deps/node/benchmark/fs/readfile-partitioned.js
new file mode 100644
index 00000000..2775793e
--- /dev/null
+++ b/deps/node/benchmark/fs/readfile-partitioned.js
@@ -0,0 +1,86 @@
+// Submit a mix of short and long jobs to the threadpool.
+// Report total job throughput.
+// If we partition the long job, overall job throughput goes up significantly.
+// However, this comes at the cost of the long job throughput.
+//
+// Short jobs: small zip jobs.
+// Long jobs: fs.readFile on a large file.
+
+'use strict';
+
+const path = require('path');
+const common = require('../common.js');
+const filename = path.resolve(__dirname,
+ `.removeme-benchmark-garbage-${process.pid}`);
+const fs = require('fs');
+const zlib = require('zlib');
+const assert = require('assert');
+
+const bench = common.createBenchmark(main, {
+ dur: [5],
+ len: [1024, 16 * 1024 * 1024],
+ concurrent: [1, 10]
+});
+
+function main(conf) {
+ const len = +conf.len;
+ try { fs.unlinkSync(filename); } catch {}
+ var data = Buffer.alloc(len, 'x');
+ fs.writeFileSync(filename, data);
+ data = null;
+
+ var zipData = Buffer.alloc(1024, 'a');
+
+ var reads = 0;
+ var zips = 0;
+ var benchEnded = false;
+ bench.start();
+ setTimeout(() => {
+ const totalOps = reads + zips;
+ benchEnded = true;
+ bench.end(totalOps);
+ try { fs.unlinkSync(filename); } catch {}
+ }, +conf.dur * 1000);
+
+ function read() {
+ fs.readFile(filename, afterRead);
+ }
+
+ function afterRead(er, data) {
+ if (er) {
+ if (er.code === 'ENOENT') {
+ // Only OK if unlinked by the timer from main.
+ assert.ok(benchEnded);
+ return;
+ }
+ throw er;
+ }
+
+ if (data.length !== len)
+ throw new Error('wrong number of bytes returned');
+
+ reads++;
+ if (!benchEnded)
+ read();
+ }
+
+ function zip() {
+ zlib.deflate(zipData, afterZip);
+ }
+
+ function afterZip(er, data) {
+ if (er)
+ throw er;
+
+ zips++;
+ if (!benchEnded)
+ zip();
+ }
+
+ // Start reads
+ var cur = +conf.concurrent;
+ while (cur--) read();
+
+ // Start a competing zip
+ zip();
+}
diff --git a/deps/node/benchmark/fs/readfile.js b/deps/node/benchmark/fs/readfile.js
new file mode 100644
index 00000000..551804b1
--- /dev/null
+++ b/deps/node/benchmark/fs/readfile.js
@@ -0,0 +1,58 @@
+// Call fs.readFile over and over again really fast.
+// Then see how many times it got called.
+// Yes, this is a silly benchmark. Most benchmarks are silly.
+'use strict';
+
+const path = require('path');
+const common = require('../common.js');
+const filename = path.resolve(process.env.NODE_TMPDIR || __dirname,
+ `.removeme-benchmark-garbage-${process.pid}`);
+const fs = require('fs');
+const assert = require('assert');
+
+const bench = common.createBenchmark(main, {
+ dur: [5],
+ len: [1024, 16 * 1024 * 1024],
+ concurrent: [1, 10]
+});
+
+function main({ len, dur, concurrent }) {
+ try { fs.unlinkSync(filename); } catch {}
+ var data = Buffer.alloc(len, 'x');
+ fs.writeFileSync(filename, data);
+ data = null;
+
+ var reads = 0;
+ var benchEnded = false;
+ bench.start();
+ setTimeout(() => {
+ benchEnded = true;
+ bench.end(reads);
+ try { fs.unlinkSync(filename); } catch {}
+ process.exit(0);
+ }, dur * 1000);
+
+ function read() {
+ fs.readFile(filename, afterRead);
+ }
+
+ function afterRead(er, data) {
+ if (er) {
+ if (er.code === 'ENOENT') {
+ // Only OK if unlinked by the timer from main.
+ assert.ok(benchEnded);
+ return;
+ }
+ throw er;
+ }
+
+ if (data.length !== len)
+ throw new Error('wrong number of bytes returned');
+
+ reads++;
+ if (!benchEnded)
+ read();
+ }
+
+ while (concurrent--) read();
+}
diff --git a/deps/node/benchmark/fs/write-stream-throughput.js b/deps/node/benchmark/fs/write-stream-throughput.js
new file mode 100644
index 00000000..bc883309
--- /dev/null
+++ b/deps/node/benchmark/fs/write-stream-throughput.js
@@ -0,0 +1,69 @@
+// Test the throughput of the fs.WriteStream class.
+'use strict';
+
+const path = require('path');
+const common = require('../common.js');
+const filename = path.resolve(process.env.NODE_TMPDIR || __dirname,
+ `.removeme-benchmark-garbage-${process.pid}`);
+const fs = require('fs');
+
+const bench = common.createBenchmark(main, {
+ dur: [5],
+ encodingType: ['buf', 'asc', 'utf'],
+ size: [2, 1024, 65535, 1024 * 1024]
+});
+
+function main({ dur, encodingType, size }) {
+ var encoding;
+
+ var chunk;
+ switch (encodingType) {
+ case 'buf':
+ chunk = Buffer.alloc(size, 'b');
+ break;
+ case 'asc':
+ chunk = 'a'.repeat(size);
+ encoding = 'ascii';
+ break;
+ case 'utf':
+ chunk = 'ü'.repeat(Math.ceil(size / 2));
+ encoding = 'utf8';
+ break;
+ default:
+ throw new Error(`invalid encodingType: ${encodingType}`);
+ }
+
+ try { fs.unlinkSync(filename); } catch {}
+
+ var started = false;
+ var ended = false;
+
+ var f = fs.createWriteStream(filename);
+ f.on('drain', write);
+ f.on('open', write);
+ f.on('close', done);
+ f.on('finish', () => {
+ ended = true;
+ const written = fs.statSync(filename).size / 1024;
+ try { fs.unlinkSync(filename); } catch {}
+ bench.end(written / 1024);
+ });
+
+
+ function write() {
+ if (!started) {
+ started = true;
+ setTimeout(() => {
+ f.end();
+ }, dur * 1000);
+ bench.start();
+ }
+
+ while (false !== f.write(chunk, encoding));
+ }
+
+ function done() {
+ if (!ended)
+ f.emit('finish');
+ }
+}