2 // If there are no args, then this is the root. Run all the benchmarks!
6 runTest(+process.argv[2], +process.argv[3], process.argv[4]);
9 var types = [ 'string', 'buffer' ];
11 var sizes = [ 1, 10, 100, 2048, 10240 ];
13 types.forEach(function(t) {
14 durs.forEach(function(d) {
15 sizes.forEach(function(s) {
16 queue.push([__filename, d, s, t]);
21 var spawn = require('child_process').spawn;
22 var node = process.execPath;
27 var args = queue.shift();
30 var child = spawn(node, args, { stdio: 'inherit' });
31 child.on('close', function(code, signal) {
33 throw new Error('Benchmark failed: ' + args.slice(1));
39 function runTest(dur, size, type) {
40 if (type !== 'string')
44 var chunk = new Array(size + 1).join('a');
47 var chunk = new Buffer(size);
53 var fs = require('fs');
54 try { fs.unlinkSync('write_stream_throughput'); } catch (e) {}
59 var time = end[0] + end[1]/1E9;
60 var written = fs.statSync('write_stream_throughput').size / 1024;
61 var rate = (written / time).toFixed(2);
62 console.log('fs_write_stream_dur_%d_size_%d_type_%s: %d',
63 dur, size, type, rate);
65 try { fs.unlinkSync('write_stream_throughput'); } catch (e) {}
68 var f = require('fs').createWriteStream('write_stream_throughput');
73 // streams2 fs.WriteStreams will let you send a lot of writes into the
74 // buffer before returning false, so capture the *actual* end time when
75 // all the bytes have been written to the disk, indicated by 'finish'
76 f.on('finish', function() {
77 end = process.hrtime(start);
82 // don't try to write after we end, even if a 'drain' event comes.
83 // v0.8 streams are so sloppy!
87 start = start || process.hrtime();
88 while (false !== f.write(chunk));
89 end = process.hrtime(start);