bench: use res.end() for chunked encoding
Use res.end() for the final chunk so we can benchmark the 'hot path' shortcut in lib/http.js that packs the headers and the body into a single packet.
This commit is contained in:
parent
04adf0e5a1
commit
ba407ce410
@ -96,13 +96,12 @@ var server = http.createServer(function (req, res) {
|
|||||||
'Transfer-Encoding': 'chunked' });
|
'Transfer-Encoding': 'chunked' });
|
||||||
// send body in chunks
|
// send body in chunks
|
||||||
var len = body.length;
|
var len = body.length;
|
||||||
var step = ~~(len / n_chunks) || len;
|
var step = Math.floor(len / n_chunks) || 1;
|
||||||
|
|
||||||
for (var i = 0; i < len; i += step) {
|
for (var i = 0, n = (n_chunks - 1); i < n; ++i) {
|
||||||
res.write(body.slice(i, i + step));
|
res.write(body.slice(i * step, i * step + step));
|
||||||
}
|
}
|
||||||
|
res.end(body.slice((n_chunks - 1) * step));
|
||||||
res.end();
|
|
||||||
} else {
|
} else {
|
||||||
var content_length = body.length.toString();
|
var content_length = body.length.toString();
|
||||||
|
|
||||||
|
@ -77,13 +77,12 @@ var server = http.createServer(function (req, res) {
|
|||||||
"Transfer-Encoding": "chunked" });
|
"Transfer-Encoding": "chunked" });
|
||||||
// send body in chunks
|
// send body in chunks
|
||||||
var len = body.length;
|
var len = body.length;
|
||||||
var step = ~~(len / n_chunks) || len;
|
var step = Math.floor(len / n_chunks) || 1;
|
||||||
|
|
||||||
for (var i = 0; i < len; i += step) {
|
for (var i = 0, n = (n_chunks - 1); i < n; ++i) {
|
||||||
res.write(body.slice(i, i + step));
|
res.write(body.slice(i * step, i * step + step));
|
||||||
}
|
}
|
||||||
|
res.end(body.slice((n_chunks - 1) * step));
|
||||||
res.end();
|
|
||||||
} else {
|
} else {
|
||||||
var content_length = body.length.toString();
|
var content_length = body.length.toString();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user