node/benchmark/fs/readfile.js
Andreas Madsen 8bb59fdb12 benchmark: missing process.exit after bench.end
Previously bench.end would call process.exit(0) however this is rather
confusing and indeed a few benchmarks had code that assumed otherwise.

This adds process.exit(0) to the benchmarks that needs it.

PR-URL: https://github.com/nodejs/node/pull/7094
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-07-26 13:21:50 +02:00

50 lines
1.1 KiB
JavaScript

// 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';
var path = require('path');
var common = require('../common.js');
var filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
var fs = require('fs');
var bench = common.createBenchmark(main, {
dur: [5],
len: [1024, 16 * 1024 * 1024],
concurrent: [1, 10]
});
function main(conf) {
var len = +conf.len;
try { fs.unlinkSync(filename); } catch (e) {}
var data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
var reads = 0;
bench.start();
setTimeout(function() {
bench.end(reads);
try { fs.unlinkSync(filename); } catch (e) {}
process.exit(0);
}, +conf.dur * 1000);
function read() {
fs.readFile(filename, afterRead);
}
function afterRead(er, data) {
if (er)
throw er;
if (data.length !== len)
throw new Error('wrong number of bytes returned');
reads++;
read();
}
var cur = +conf.concurrent;
while (cur--) read();
}