mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
a52878c239
PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
42 lines
978 B
JavaScript
42 lines
978 B
JavaScript
// 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.
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1, 4, 8, 16],
|
|
len: [1, 64, 256],
|
|
c: [100]
|
|
});
|
|
|
|
function main({ len, n, c }) {
|
|
const http = require('http');
|
|
const chunk = Buffer.alloc(len, '8');
|
|
|
|
const server = http.createServer(function(req, res) {
|
|
function send(left) {
|
|
if (left === 0) return res.end();
|
|
res.write(chunk);
|
|
setTimeout(function() {
|
|
send(left - 1);
|
|
}, 0);
|
|
}
|
|
send(n);
|
|
});
|
|
|
|
server.listen(common.PORT, function() {
|
|
bench.http({
|
|
connections: c
|
|
}, function() {
|
|
server.close();
|
|
});
|
|
});
|
|
}
|