MCPcopy Create free account
hub / github.com/restify/node-restify / runBenchmark

Function runBenchmark

benchmark/lib/bench.js:10–76  ·  view source on GitHub ↗
(opts, handler, version, cb)

Source from the content-addressed store, hash-verified

8var pipeline = require('vasync').pipeline;
9
10function runBenchmark(opts, handler, version, cb) {
11 if (opts.track) {
12 console.log(version.toUpperCase() + ':');
13 }
14
15 var spinner = ora('Started ' + version + '/' + handler).start();
16 var modulePath = path.join(__dirname, '../benchmarks', handler);
17 var url = require(modulePath).url;
18 var forked = fork(modulePath, ['version=' + version]);
19
20 pipeline(
21 {
22 funcs: [
23 function warm(_, callback) {
24 spinner.color = 'magenta';
25 spinner.text =
26 'Warming ' + version + '/' + handler + ' for 5s';
27
28 var fireOpts = Object.assign({}, opts, {
29 duration: 5,
30 url: url
31 });
32 autocannon.fire(
33 fireOpts,
34 handler,
35 version,
36 false,
37 callback
38 );
39 },
40
41 function benchmark(_, callback) {
42 if (opts.track) {
43 spinner.stop();
44 } else {
45 spinner.color = 'yellow';
46 spinner.text =
47 'Benchmarking ' +
48 version +
49 '/' +
50 handler +
51 ' for ' +
52 opts.duration +
53 's';
54 }
55
56 var fireOpts = Object.assign({}, opts, { url: url });
57 autocannon.fire(fireOpts, handler, version, true, callback);
58 }
59 ]
60 },
61 function onPipelineFinished(err) {
62 forked.kill('SIGINT');
63
64 if (err) {
65 spinner.fail();
66 cb(err);
67 return;

Callers 1

startFunction · 0.85

Calls 1

cbFunction · 0.85

Tested by

no test coverage detected