Sha256: 1ec87ade248ef289ba768658fe0a827d87c405327ce5f2e13ec88dac5c07c4c4

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

// Measure the time it takes for the HTTP client to send a request body.
'use strict';

var common = require('../common.js');
var http = require('http');

var bench = common.createBenchmark(main, {
  dur: [5],
  type: ['asc', 'utf', 'buf'],
  bytes: [32, 256, 1024],
  method: ['write', 'end']
});

function main(conf) {
  var dur = +conf.dur;
  var len = +conf.bytes;

  var encoding;
  var chunk;
  switch (conf.type) {
    case 'buf':
      chunk = Buffer.alloc(len, 'x');
      break;
    case 'utf':
      encoding = 'utf8';
      chunk = new Array(len / 2 + 1).join('ΓΌ');
      break;
    case 'asc':
      chunk = new Array(len + 1).join('a');
      break;
  }

  var nreqs = 0;
  var options = {
    headers: { 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked' },
    agent: new http.Agent({ maxSockets: 1 }),
    host: '127.0.0.1',
    port: common.PORT,
    path: '/',
    method: 'POST'
  };

  var server = http.createServer(function(req, res) {
    res.end();
  });
  server.listen(options.port, options.host, function() {
    setTimeout(done, dur * 1000);
    bench.start();
    pummel();
  });

  function pummel() {
    var req = http.request(options, function(res) {
      nreqs++;
      pummel();  // Line up next request.
      res.resume();
    });
    if (conf.method === 'write') {
      req.write(chunk, encoding);
      req.end();
    } else {
      req.end(chunk, encoding);
    }
  }

  function done() {
    bench.end(nreqs);
    process.exit(0);
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/benchmark/http/client-request-body.js
node-compiler-0.9.0 vendor/node-v7.2.1/benchmark/http/client-request-body.js
node-compiler-0.8.0 vendor/node-v7.2.0/benchmark/http/client-request-body.js
node-compiler-0.7.0 vendor/node-v7.1.0/benchmark/http/client-request-body.js