diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 1b3cee7f4fd..236b046e92d 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -96,13 +96,12 @@ var server = http.createServer(function (req, res) { 'Transfer-Encoding': 'chunked' }); // send body in chunks 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) { - res.write(body.slice(i, i + step)); + for (var i = 0, n = (n_chunks - 1); i < n; ++i) { + res.write(body.slice(i * step, i * step + step)); } - - res.end(); + res.end(body.slice((n_chunks - 1) * step)); } else { var content_length = body.length.toString(); diff --git a/benchmark/http_simple_auto.js b/benchmark/http_simple_auto.js index 31926351fb1..f72cc01e60a 100644 --- a/benchmark/http_simple_auto.js +++ b/benchmark/http_simple_auto.js @@ -77,13 +77,12 @@ var server = http.createServer(function (req, res) { "Transfer-Encoding": "chunked" }); // send body in chunks 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) { - res.write(body.slice(i, i + step)); + for (var i = 0, n = (n_chunks - 1); i < n; ++i) { + res.write(body.slice(i * step, i * step + step)); } - - res.end(); + res.end(body.slice((n_chunks - 1) * step)); } else { var content_length = body.length.toString();