2013-04-09 00:04:38 +02:00
|
|
|
// When calling .end(buffer) right away, this triggers a "hot path"
|
|
|
|
// optimization in http.js, to avoid an extra write call.
|
|
|
|
//
|
|
|
|
// However, the overhead of copying a large buffer is higher than
|
|
|
|
// the overhead of an extra write() call, so the hot path was not
|
|
|
|
// always as hot as it could be.
|
|
|
|
//
|
|
|
|
// Verify that our assumptions are valid.
|
2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2013-04-09 00:04:38 +02:00
|
|
|
|
|
|
|
var common = require('../common.js');
|
|
|
|
|
|
|
|
var bench = common.createBenchmark(main, {
|
2017-03-29 17:31:31 +02:00
|
|
|
n: [1, 4, 8, 16],
|
|
|
|
len: [1, 64, 256],
|
2013-04-09 00:04:38 +02:00
|
|
|
c: [100]
|
|
|
|
});
|
|
|
|
|
|
|
|
function main(conf) {
|
2016-02-20 02:03:16 +01:00
|
|
|
const http = require('http');
|
2017-03-29 17:31:31 +02:00
|
|
|
var chunk = Buffer.alloc(conf.len, '8');
|
2013-04-09 00:04:38 +02:00
|
|
|
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
function send(left) {
|
|
|
|
if (left === 0) return res.end();
|
|
|
|
res.write(chunk);
|
|
|
|
setTimeout(function() {
|
|
|
|
send(left - 1);
|
|
|
|
}, 0);
|
|
|
|
}
|
2017-03-29 17:31:31 +02:00
|
|
|
send(conf.n);
|
2013-04-09 00:04:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
server.listen(common.PORT, function() {
|
2016-08-05 11:34:50 +02:00
|
|
|
bench.http({
|
|
|
|
connections: conf.c
|
|
|
|
}, function() {
|
2013-04-09 00:04:38 +02:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|