Sha256: bf82052eb44b8fec84e5cc4a627317c6e346bb843e952b5ae51096604619632a
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
// 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. 'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { type: ['asc', 'utf', 'buf'], kb: [64, 128, 256, 1024], c: [100], method: ['write', 'end'] }); function main(conf) { const http = require('http'); var chunk; var len = conf.kb * 1024; switch (conf.type) { case 'buf': chunk = Buffer.alloc(len, 'x'); break; case 'utf': 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(); }); }); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
node-compiler-0.7.0 | vendor/node-v6.9.1/benchmark/http/end-vs-write-end.js |