doc: document directories in test directory
[platform/upstream/nodejs.git] / benchmark / http / chunked.js
1 // When calling .end(buffer) right away, this triggers a "hot path"
2 // optimization in http.js, to avoid an extra write call.
3 //
4 // However, the overhead of copying a large buffer is higher than
5 // the overhead of an extra write() call, so the hot path was not
6 // always as hot as it could be.
7 //
8 // Verify that our assumptions are valid.
9
10 var common = require('../common.js');
11 var PORT = common.PORT;
12
13 var bench = common.createBenchmark(main, {
14   num: [1, 4, 8, 16],
15   size: [1, 64, 256],
16   c: [100]
17 });
18
19 function main(conf) {
20   http = require('http');
21   var chunk = new Buffer(conf.size);
22   chunk.fill('8');
23
24   var args = ['-d', '10s', '-t', 8, '-c', conf.c];
25
26   var server = http.createServer(function(req, res) {
27     function send(left) {
28       if (left === 0) return res.end();
29       res.write(chunk);
30       setTimeout(function() {
31         send(left - 1);
32       }, 0);
33     }
34     send(conf.num);
35   });
36
37   server.listen(common.PORT, function() {
38     bench.http('/', args, function() {
39       server.close();
40     });
41   });
42 }