0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/http/chunked.js
Ruben Bridgewater a52878c239
benchmark: (http) use destructuring
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>
2018-01-23 01:29:28 +01:00

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();
});
});
}