diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-17 22:38:30 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-17 23:26:23 +0200 |
commit | 63607a0304e99259d3b7a24c44f7d29384b93cb4 (patch) | |
tree | 73c6fa5c45954a1b74f3ac71e9603b2c2b4434f7 /benchmark | |
parent | 8e8f36f9583cd4b0c1c76b5640a409647d0c260c (diff) | |
download | android-node-v8-63607a0304e99259d3b7a24c44f7d29384b93cb4.tar.gz android-node-v8-63607a0304e99259d3b7a24c44f7d29384b93cb4.tar.bz2 android-node-v8-63607a0304e99259d3b7a24c44f7d29384b93cb4.zip |
bench: make number of response body chunks configurable in http_simple
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/http_simple.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 300bf14450..cac406ce7f 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -39,7 +39,7 @@ var server = http.createServer(function (req, res) { var command = commands[1]; var body = ""; var arg = commands[2]; - var chunked = (commands[3] === "chunked"); + var n_chunks = parseInt(commands[3], 10); var status = 200; if (command == "bytes") { @@ -82,18 +82,28 @@ var server = http.createServer(function (req, res) { body = "not found\n"; } - if (chunked) { + // example: http://localhost:port/bytes/512/4 + // sends a 512 byte body in 4 chunks of 128 bytes + if (n_chunks > 0) { res.writeHead(status, { "Content-Type": "text/plain", "Transfer-Encoding": "chunked" }); + // send body in chunks + var len = body.length; + var step = ~~(len / n_chunks) || len; + + for (var i = 0; i < len; i += step) { + res.write(body.slice(i, i + step)); + } + + res.end(); } else { var content_length = body.length.toString(); res.writeHead(status, { "Content-Type": "text/plain", "Content-Length": content_length }); + res.end(body); } - res.end(body); - }); server.listen(port, function () { |