How to use the autocannon function in autocannon

To help you get started, we’ve selected a few autocannon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dazejs / daze / tools / benchmarks / benchmarks.ts View on Github external
async function run(lib: string, url: string) {
  const _targetPath = path.join(basePath, lib)

  const child = childProcess.spawn('node', [_targetPath], {
    stdio: 'inherit',
  });
  await sleep(2000)

  benchmarksMDStream.write('\n')
  benchmarksMDStream.write(`### ${lib}\n`)
  benchmarksMDStream.write('\n')

  const { requests, throughput } = await autocannon({
    ...opt,
    url,
  })
  child.kill()

  benchmarksMDStream.write(table([
    ['Stat', 'Avg', 'Stdev', 'Min'],
    ['Req/Sec', requests.average, requests.stddev, requests.min],
    ['Bytes/Sec', size(throughput.average), size(requests.stddev), size(requests.min)]
  ]))
  benchmarksMDStream.write('\n')
  benchmarksMDStream.write('\n')
}
github strongloop / loopback-next / benchmark / src / autocannon.ts View on Github external
title: string,
    urlPath: string,
    options: Omit = {},
  ): Promise {
    const config = {
      url: this.buildUrl(urlPath),
      duration: this.duration,
      title,
      ...options,
      headers: {
        'content-type': 'application/json',
        ...options.headers,
      },
    };

    const data = await autocannon(config);
    assert.equal(
      data.non2xx,
      0,
      'No request should have failed with non-2xx status code.',
    );
    const stats: EndpointStats = {
      requestsPerSecond: data.requests.average,
      latency: data.latency.average,
    };
    return stats;
  }

autocannon

Fast HTTP benchmarking tool written in Node.js

MIT
Latest version published 3 months ago

Package Health Score

86 / 100
Full package analysis

Popular autocannon functions