Skip to content

Commit f2d5cea

Browse files
committed
benchmark: add chunked-encoding benchmark
1 parent 0c72936 commit f2d5cea

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

benchmark/http/chunked.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 = ['-r', 5000, '-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+
}

0 commit comments

Comments
 (0)