2013-02-12 08:55:36 +01:00
|
|
|
// 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.
|
2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2013-02-12 08:55:36 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const path = require('path');
|
|
|
|
const common = require('../common.js');
|
2017-12-22 00:04:24 +01:00
|
|
|
const filename = path.resolve(process.env.NODE_TMPDIR || __dirname,
|
2017-11-05 11:12:23 +01:00
|
|
|
`.removeme-benchmark-garbage-${process.pid}`);
|
2017-09-14 03:48:53 +02:00
|
|
|
const fs = require('fs');
|
2013-02-12 08:55:36 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2013-02-20 00:03:41 +01:00
|
|
|
dur: [5],
|
2013-02-12 08:55:36 +01:00
|
|
|
len: [1024, 16 * 1024 * 1024],
|
|
|
|
concurrent: [1, 10]
|
|
|
|
});
|
|
|
|
|
|
|
|
function main(conf) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const len = +conf.len;
|
2013-02-12 08:55:36 +01:00
|
|
|
try { fs.unlinkSync(filename); } catch (e) {}
|
2016-01-26 00:00:06 +01:00
|
|
|
var data = Buffer.alloc(len, 'x');
|
2013-02-12 08:55:36 +01:00
|
|
|
fs.writeFileSync(filename, data);
|
|
|
|
data = null;
|
|
|
|
|
|
|
|
var reads = 0;
|
2016-07-21 13:08:28 +02:00
|
|
|
var bench_ended = false;
|
2013-02-12 08:55:36 +01:00
|
|
|
bench.start();
|
|
|
|
setTimeout(function() {
|
2016-07-21 13:08:28 +02:00
|
|
|
bench_ended = true;
|
2013-02-12 08:55:36 +01:00
|
|
|
bench.end(reads);
|
|
|
|
try { fs.unlinkSync(filename); } catch (e) {}
|
2016-05-31 21:49:16 +02:00
|
|
|
process.exit(0);
|
2013-02-12 08:55:36 +01:00
|
|
|
}, +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++;
|
2016-07-21 13:08:28 +02:00
|
|
|
if (!bench_ended)
|
|
|
|
read();
|
2013-02-12 08:55:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var cur = +conf.concurrent;
|
|
|
|
while (cur--) read();
|
|
|
|
}
|