0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/benchmark/http/chunked.js
James M Snell 85ab4a5f12 buffer: add .from(), .alloc() and .allocUnsafe()
Several changes:

* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs

PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2016-03-16 08:34:02 -07:00

42 lines
1010 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';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
num: [1, 4, 8, 16],
size: [1, 64, 256],
c: [100]
});
function main(conf) {
const http = require('http');
var chunk = Buffer.alloc(conf.size, '8');
var args = ['-d', '10s', '-t', 8, '-c', conf.c];
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);
}
send(conf.num);
});
server.listen(common.PORT, function() {
bench.http('/', args, function() {
server.close();
});
});
}