0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/http/end-vs-write-end.js
Brendan Ashworth 083c421b5c benchmark: remove extra spacing in http options
This commit removes the benchmark spacing modification in
`client-request-body.js` and `end-vs-write-end.js` which adds two spaces
to the end of some variables to make sure the lines line up.

The reason behind this is that its totally pointless (the lines don't
actually line up with it) and it disallows you to parse the output with
a tool like awk, or at least makes it a lot harder.

PR-URL: https://github.com/iojs/io.js/pull/650
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-01-30 16:09:10 -05:00

60 lines
1.3 KiB
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.
var common = require('../common.js');
var PORT = common.PORT;
var bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'],
kb: [64, 128, 256, 1024],
c: [100],
method: ['write', 'end']
});
function main(conf) {
http = require('http');
var chunk;
var len = conf.kb * 1024;
switch (conf.type) {
case 'buf':
chunk = new Buffer(len);
chunk.fill('x');
break;
case 'utf':
encoding = 'utf8';
chunk = new Array(len / 2 + 1).join('ü');
break;
case 'asc':
chunk = new Array(len + 1).join('a');
break;
}
function write(res) {
res.write(chunk);
res.end();
}
function end(res) {
res.end(chunk);
}
var method = conf.method === 'write' ? write : end;
var args = ['-d', '10s', '-t', 8, '-c', conf.c];
var server = http.createServer(function(req, res) {
method(res);
});
server.listen(common.PORT, function() {
bench.http('/', args, function() {
server.close();
});
});
}