GeezerVison is showing github.com — test: create shared runBenchmark function · nodejs/node@45cdbcf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/README.md +12Lines changed: 12 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,9 +4,21 @@ This directory contains modules used to test the Node.js implementation. | 4 | 4 |
| 5 | 5 | ## Table of Contents | 6 | 6 |
| | 7 | +* [Benchmark module](#benchmark-module) | 7 | 8 | * [Common module API](#common-module-api) | 8 | 9 | * [WPT module](#wpt-module) | 9 | 10 |
| | 11 | +## Benchmark Module | | 12 | + | | 13 | +The `benchmark` module is used by tests to run benchmarks. | | 14 | + | | 15 | +### runBenchmark(name, args, env) | | 16 | + | | 17 | +* `name` [<String>] Name of benchmark suite to be run. | | 18 | +* `args` [<Array>] Array of environment variable key/value pairs (ex: | | 19 | + `n=1`) to be applied via `--set`. | | 20 | +* `env` [<Object>] Environment variables to be applied during the run. | | 21 | + | 10 | 22 | ## Common Module API | 11 | 23 |
| 12 | 24 | The `common` module is used by tests for consistency across repeated | |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/* eslint-disable required-modules */ | | 2 | + | | 3 | +'use strict'; | | 4 | + | | 5 | +const assert = require('assert'); | | 6 | +const fork = require('child_process').fork; | | 7 | +const path = require('path'); | | 8 | + | | 9 | +const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | | 10 | + | | 11 | +function runBenchmark(name, args, env) { | | 12 | + const argv = []; | | 13 | + | | 14 | + for (let i = 0; i < args.length; i++) { | | 15 | + argv.push('--set'); | | 16 | + argv.push(args[i]); | | 17 | + } | | 18 | + | | 19 | + argv.push(name); | | 20 | + | | 21 | + const mergedEnv = Object.assign({}, process.env, env); | | 22 | + | | 23 | + const child = fork(runjs, argv, { env: mergedEnv }); | | 24 | + child.on('exit', (code, signal) => { | | 25 | + assert.strictEqual(code, 0); | | 26 | + assert.strictEqual(signal, null); | | 27 | + }); | | 28 | +} | | 29 | + | | 30 | +module.exports = runBenchmark; |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-arrays.js +2-16Lines changed: 2 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for arrays benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | | 5 | +const runBenchmark = require('../common/benchmark'); | 7 | 6 |
| 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'n=1', | 14 | | - '--set', 'type=Array', | 15 | | - 'arrays']; | 16 | | - | 17 | | -const child = fork(runjs, argv); | 18 | | -child.on('exit', (code, signal) => { | 19 | | - assert.strictEqual(code, 0); | 20 | | - assert.strictEqual(signal, null); | 21 | | -}); | | 7 | +runBenchmark('arrays', ['n=1', 'type=Array']); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-cluster.js +2-17Lines changed: 2 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for cluster benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | | 5 | +const runBenchmark = require('../common/benchmark'); | 7 | 6 |
| 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'n=1', | 14 | | - '--set', 'payload=string', | 15 | | - '--set', 'sendsPerBroadcast=1', | 16 | | - 'cluster']; | 17 | | - | 18 | | -const child = fork(runjs, argv); | 19 | | -child.on('exit', (code, signal) => { | 20 | | - assert.strictEqual(code, 0); | 21 | | - assert.strictEqual(signal, null); | 22 | | -}); | | 7 | +runBenchmark('cluster', ['n=1', 'payload=string', 'sendsPerBroadcast=1']); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-crypto.js +15-26Lines changed: 15 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,29 +8,18 @@ if (!common.hasCrypto) | 8 | 8 | if (common.hasFipsCrypto) | 9 | 9 | common.skip('some benchmarks are FIPS-incompatible'); | 10 | 10 |
| 11 | | -// Minimal test for crypto benchmarks. This makes sure the benchmarks aren't | 12 | | -// horribly broken but nothing more than that. | 13 | | - | 14 | | -const assert = require('assert'); | 15 | | -const fork = require('child_process').fork; | 16 | | -const path = require('path'); | 17 | | - | 18 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 19 | | -const argv = ['--set', 'algo=sha256', | 20 | | - '--set', 'api=stream', | 21 | | - '--set', 'keylen=1024', | 22 | | - '--set', 'len=1', | 23 | | - '--set', 'n=1', | 24 | | - '--set', 'out=buffer', | 25 | | - '--set', 'type=buf', | 26 | | - '--set', 'v=crypto', | 27 | | - '--set', 'writes=1', | 28 | | - 'crypto']; | 29 | | - | 30 | | -const child = fork(runjs, argv, { env: Object.assign({}, process.env, { | 31 | | - NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }) }); | 32 | | - | 33 | | -child.on('exit', (code, signal) => { | 34 | | - assert.strictEqual(code, 0); | 35 | | - assert.strictEqual(signal, null); | 36 | | -}); | | 11 | +const runBenchmark = require('../common/benchmark'); | | 12 | + | | 13 | +runBenchmark('crypto', | | 14 | + [ | | 15 | + 'n=1', | | 16 | + 'algo=sha256', | | 17 | + 'api=stream', | | 18 | + 'keylen=1024', | | 19 | + 'len=1', | | 20 | + 'out=buffer', | | 21 | + 'type=buf', | | 22 | + 'v=crypto', | | 23 | + 'writes=1' | | 24 | + ], | | 25 | + { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-dns.js +2-19Lines changed: 2 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for dns benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | 7 | | - | 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | | 5 | +const runBenchmark = require('../common/benchmark'); | 13 | 6 |
| 14 | 7 | const env = Object.assign({}, process.env, | 15 | 8 | { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); | 16 | 9 |
| 17 | | -const child = fork(runjs, | 18 | | - ['--set', 'n=1', | 19 | | - '--set', 'all=false', | 20 | | - '--set', 'name=127.0.0.1', | 21 | | - 'dns'], | 22 | | - { env }); | 23 | | - | 24 | | -child.on('exit', (code, signal) => { | 25 | | - assert.strictEqual(code, 0); | 26 | | - assert.strictEqual(signal, null); | 27 | | -}); | | 10 | +runBenchmark('dns', ['n=1', 'all=false', 'name=127.0.0.1'], env); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-domain.js +2-16Lines changed: 2 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for domain benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | | 5 | +const runBenchmark = require('../common/benchmark'); | 7 | 6 |
| 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'arguments=0', | 14 | | - '--set', 'n=1', | 15 | | - 'domain']; | 16 | | - | 17 | | -const child = fork(runjs, argv); | 18 | | -child.on('exit', (code, signal) => { | 19 | | - assert.strictEqual(code, 0); | 20 | | - assert.strictEqual(signal, null); | 21 | | -}); | | 7 | +runBenchmark('domain', ['n=1', 'arguments=0']); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-events.js +2-15Lines changed: 2 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for events benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | | 5 | +const runBenchmark = require('../common/benchmark'); | 7 | 6 |
| 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'n=1', | 14 | | - 'events']; | 15 | | - | 16 | | -const child = fork(runjs, argv); | 17 | | -child.on('exit', (code, signal) => { | 18 | | - assert.strictEqual(code, 0); | 19 | | - assert.strictEqual(signal, null); | 20 | | -}); | | 7 | +runBenchmark('events', ['n=1']); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-os.js +2-15Lines changed: 2 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for os benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | | 5 | +const runBenchmark = require('../common/benchmark'); | 7 | 6 |
| 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'n=1', | 14 | | - 'os']; | 15 | | - | 16 | | -const child = fork(runjs, argv); | 17 | | -child.on('exit', (code, signal) => { | 18 | | - assert.strictEqual(code, 0); | 19 | | - assert.strictEqual(signal, null); | 20 | | -}); | | 7 | +runBenchmark('os', ['n=1']); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-path.js +10-20Lines changed: 10 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | | -// Minimal test for path benchmarks. This makes sure the benchmarks aren't | 6 | | -// horribly broken but nothing more than that. | 7 | | - | 8 | | -const assert = require('assert'); | 9 | | -const fork = require('child_process').fork; | 10 | | -const path = require('path'); | 11 | | - | 12 | | -const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); | 13 | | -const argv = ['--set', 'n=1', | 14 | | - '--set', 'path=', | 15 | | - '--set', 'pathext=', | 16 | | - '--set', 'paths=', | 17 | | - '--set', 'props=', | 18 | | - 'path']; | 19 | | - | 20 | | -const child = fork(runjs, argv); | 21 | | -child.on('exit', (code, signal) => { | 22 | | - assert.strictEqual(code, 0); | 23 | | - assert.strictEqual(signal, null); | 24 | | -}); | | 5 | +const runBenchmark = require('../common/benchmark'); | | 6 | + | | 7 | +runBenchmark('path', | | 8 | + [ | | 9 | + 'n=1', | | 10 | + 'path=', | | 11 | + 'pathext=', | | 12 | + 'paths=', | | 13 | + 'props=' | | 14 | + ]); |
|