Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test, benchmark: create shared runBenchmark func
Mostly shared/duplicated logic between all benchmark test files, so
creating a new common module to store it.
  • Loading branch information
maclover7 committed Sep 8, 2017
commit 7ab16191c9b36428d58b1ede1301930c70424f29
28 changes: 28 additions & 0 deletions test/common/benchmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will need a /* eslint-disable required-modules */ at the top to pass linting.
Please run make lint to make sure :-)


const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

function runBenchmark(name, args, env) {
const argv = [];

for (let i = 0; i < args.length; i++) {
argv.push('--set');
argv.push(args[i]);
}

argv.push(name);

const mergedEnv = Object.assign({}, process.env, env);

const child = fork(runjs, argv, { env: mergedEnv });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}

module.exports = runBenchmark;
21 changes: 2 additions & 19 deletions test/parallel/test-benchmark-cluster.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
'use strict';

require('../common');
const runBenchmark = require('../common/benchmarks');

// Minimal test for cluster benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'--set', 'payload=string',
'--set', 'sendsPerBroadcast=1',
'cluster'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
runBenchmark('cluster', ['n=1', 'payload=string', 'sendsPerBroadcast=1']);
41 changes: 15 additions & 26 deletions test/parallel/test-benchmark-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,18 @@ if (!common.hasCrypto)
if (common.hasFipsCrypto)
common.skip('some benchmarks are FIPS-incompatible');

// Minimal test for crypto benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'algo=sha256',
'--set', 'api=stream',
'--set', 'keylen=1024',
'--set', 'len=1',
'--set', 'n=1',
'--set', 'out=buffer',
'--set', 'type=buf',
'--set', 'v=crypto',
'--set', 'writes=1',
'crypto'];

const child = fork(runjs, argv, { env: Object.assign({}, process.env, {
NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }) });

child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('cluster',
[
'n=1',
'algo=sha256',
'api=stream',
'keylen=1024',
'len=1',
'out=buffer',
'type=buf',
'v=crypto',
'writes=1'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
20 changes: 2 additions & 18 deletions test/parallel/test-benchmark-domain.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
'use strict';

require('../common');
const runBenchmark = require('../common/benchmarks');

// Minimal test for domain benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'arguments=0',
'--set', 'n=1',
'domain'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
runBenchmark('domain', ['n=1', 'arguments=0']);
19 changes: 2 additions & 17 deletions test/parallel/test-benchmark-events.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
'use strict';

require('../common');
const runBenchmark = require('../common/benchmarks');

// Minimal test for events benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'events'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
runBenchmark('events', ['n=1']);
19 changes: 2 additions & 17 deletions test/parallel/test-benchmark-os.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
'use strict';

require('../common');
const runBenchmark = require('../common/benchmarks');

// Minimal test for os benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'os'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
runBenchmark('os', ['n=1']);
32 changes: 10 additions & 22 deletions test/parallel/test-benchmark-path.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
'use strict';

require('../common');

// Minimal test for path benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'--set', 'path=',
'--set', 'pathext=',
'--set', 'paths=',
'--set', 'props=',
'path'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('path',
[
'n=1',
'path=',
'pathext=',
'paths=',
'props='
]);
28 changes: 8 additions & 20 deletions test/parallel/test-benchmark-process.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
'use strict';

require('../common');

// Minimal test for process benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'millions=0.000001',
'--set', 'n=1',
'--set', 'type=raw',
'process'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('process',
[
'millions=0.000001',
'n=1',
'type=raw'
]);
32 changes: 9 additions & 23 deletions test/parallel/test-benchmark-timers.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
'use strict';

require('../common');

// Minimal test for timers benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'type=depth',
'--set', 'millions=0.000001',
'--set', 'thousands=0.001',
'timers'];

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('timers',
[
'type=depth',
'millions=0.000001',
'thousands=0.001'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
30 changes: 9 additions & 21 deletions test/parallel/test-benchmark-zlib.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
'use strict';

require('../common');

// Minimal test for zlib benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'method=deflate',
'--set', 'n=1',
'--set', 'options=true',
'--set', 'type=Deflate',
'zlib'];

const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('zlib',
[
'method=deflate',
'n=1',
'options=true',
'type=Deflate'
]);
39 changes: 11 additions & 28 deletions test/sequential/test-benchmark-child-process.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
'use strict';

require('../common');

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(
runjs,
[
'--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'
],
{ env }
);

child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('child_process',
[
'dur=0',
'n=1',
'len=1',
'params=1',
'methodName=execSync',
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
44 changes: 16 additions & 28 deletions test/sequential/test-benchmark-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,23 @@ const common = require('../common');
if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP benchmark test');

// Minimal test for http benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.

// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.

const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');

const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');

const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

const child = fork(runjs, ['--set', 'benchmarker=test-double',
'--set', 'c=1',
'--set', 'chunkedEnc=true',
'--set', 'chunks=0',
'--set', 'dur=0.1',
'--set', 'key=""',
'--set', 'len=1',
'--set', 'method=write',
'--set', 'n=1',
'--set', 'res=normal',
'http'],
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
const runBenchmark = require('../common/benchmarks');

runBenchmark('http',
[
'benchmarker=test-double',
'c=1',
'chunkedEnc=true',
'chunks=0',
'dur=0.1',
'key=""',
'len=1',
'method=write',
'n=1',
'res=normal'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
Loading