Skip to content

Commit 6d116be

Browse files
committed
bench: Move fs-readfile.js to fs/readfile.js
1 parent 844b332 commit 6d116be

2 files changed

Lines changed: 48 additions & 72 deletions

File tree

benchmark/fs-readfile.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

benchmark/fs/readfile.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Call fs.readFile over and over again really fast.
2+
// Then see how many times it got called.
3+
// Yes, this is a silly benchmark. Most benchmarks are silly.
4+
5+
var path = require('path');
6+
var common = require('../common.js');
7+
var filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
8+
var fs = require('fs');
9+
10+
var bench = common.createBenchmark(main, {
11+
dur: [1, 3],
12+
len: [1024, 16 * 1024 * 1024],
13+
concurrent: [1, 10]
14+
});
15+
16+
function main(conf) {
17+
var len = +conf.len;
18+
try { fs.unlinkSync(filename); } catch (e) {}
19+
var data = new Buffer(len);
20+
data.fill('x');
21+
fs.writeFileSync(filename, data);
22+
data = null;
23+
24+
var reads = 0;
25+
bench.start();
26+
setTimeout(function() {
27+
bench.end(reads);
28+
try { fs.unlinkSync(filename); } catch (e) {}
29+
}, +conf.dur * 1000);
30+
31+
function read() {
32+
fs.readFile(filename, afterRead);
33+
}
34+
35+
function afterRead(er, data) {
36+
if (er)
37+
throw er;
38+
39+
if (data.length !== len)
40+
throw new Error('wrong number of bytes returned');
41+
42+
reads++;
43+
read();
44+
}
45+
46+
var cur = +conf.concurrent;
47+
while (cur--) read();
48+
}

0 commit comments

Comments
 (0)