diff options
author | isaacs <i@izs.me> | 2013-02-11 23:55:36 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-02-19 14:14:35 -0800 |
commit | 6d116be7cf26abf3a4940e9e75ec329248de96d8 (patch) | |
tree | 5b2f58c98715f7022a7b4cf4d9275f9ddae04b59 /benchmark/fs | |
parent | 844b33205c77fe32d2aae76209eb444044b9aeff (diff) | |
download | android-node-v8-6d116be7cf26abf3a4940e9e75ec329248de96d8.tar.gz android-node-v8-6d116be7cf26abf3a4940e9e75ec329248de96d8.tar.bz2 android-node-v8-6d116be7cf26abf3a4940e9e75ec329248de96d8.zip |
bench: Move fs-readfile.js to fs/readfile.js
Diffstat (limited to 'benchmark/fs')
-rw-r--r-- | benchmark/fs/readfile.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js new file mode 100644 index 0000000000..38548ef647 --- /dev/null +++ b/benchmark/fs/readfile.js @@ -0,0 +1,48 @@ +// 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. + +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: [1, 3], + len: [1024, 16 * 1024 * 1024], + concurrent: [1, 10] +}); + +function main(conf) { + var len = +conf.len; + try { fs.unlinkSync(filename); } catch (e) {} + var data = new Buffer(len); + data.fill('x'); + fs.writeFileSync(filename, data); + data = null; + + var reads = 0; + bench.start(); + setTimeout(function() { + bench.end(reads); + try { fs.unlinkSync(filename); } catch (e) {} + }, +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(); +} |