summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2013-04-09 02:04:38 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2013-04-27 21:03:40 +0400
commitf2d5cea73a53c59ce6314ecdf27bbf341e0465a2 (patch)
tree92315b7473b858beb2dec98597e9f5e7c45e3d6a
parent0c7293664197e58771861ab8c1f212cf5dbcadd7 (diff)
downloadnode-f2d5cea73a53c59ce6314ecdf27bbf341e0465a2.tar.gz
benchmark: add chunked-encoding benchmark
-rw-r--r--benchmark/http/chunked.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js
new file mode 100644
index 000000000..bead074dc
--- /dev/null
+++ b/benchmark/http/chunked.js
@@ -0,0 +1,42 @@
+// 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, {
+ num: [1, 4, 8, 16],
+ size: [1, 64, 256],
+ c: [100]
+});
+
+function main(conf) {
+ http = require('http');
+ var chunk = new Buffer(conf.size);
+ chunk.fill('8');
+
+ var args = ['-r', 5000, '-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();
+ });
+ });
+}