Revert "benchmark: remove special test entries"

This reverts commit 357230f4b7.

Refs: https://github.com/nodejs/node/pull/31396
PR-URL: https://github.com/nodejs/node/pull/31722
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Anna Henningsen
2020-02-10 20:03:44 +01:00
parent 2abf0afb2b
commit 7cfbc9f90f
41 changed files with 81 additions and 15 deletions

View File

@@ -6,10 +6,12 @@ const bench = common.createBenchmark(main, {
n: [2e4],
len: [1e2, 1e3],
strict: [0, 1],
method: ['deepEqual', 'notDeepEqual'],
method: [ 'deepEqual', 'notDeepEqual' ],
});
function main({ len, n, method, strict }) {
if (!method)
method = 'deepEqual';
const data = Buffer.allocUnsafe(len + 1);
const actual = Buffer.alloc(len);
const expected = Buffer.alloc(len);

View File

@@ -34,6 +34,8 @@ function main({ n, len, method, strict }) {
const array = Array(len).fill(1);
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => [`str_${i}`, 123]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);

View File

@@ -7,7 +7,7 @@ const bench = common.createBenchmark(main, {
n: [5e3],
size: [1e2, 1e3, 5e4],
strict: [0, 1],
method: ['deepEqual', 'notDeepEqual'],
method: [ 'deepEqual', 'notDeepEqual' ],
});
function createObj(source, add = '') {
@@ -27,6 +27,9 @@ function main({ size, n, method, strict }) {
// TODO: Fix this "hack". `n` should not be manipulated.
n = Math.min(Math.ceil(n / size), 20);
if (!method)
method = 'deepEqual';
const source = Array.apply(null, Array(size));
const actual = createObj(source);
const expected = createObj(source);

View File

@@ -52,6 +52,8 @@ function main({ n, len, primitive, method, strict }) {
const expectedWrongSet = new Set(expectedWrong);
switch (method) {
// Empty string falls through to next line as default, mostly for tests.
case '':
case 'deepEqual_Array':
run(strict ? deepStrictEqual : deepEqual, n, actual, expected);
break;

View File

@@ -13,10 +13,12 @@ const bench = common.createBenchmark(main, {
primitive: Object.keys(primValues),
n: [2e4],
strict: [0, 1],
method: ['deepEqual', 'notDeepEqual'],
method: [ 'deepEqual', 'notDeepEqual' ],
});
function main({ n, primitive, method, strict }) {
if (!method)
method = 'deepEqual';
const prim = primValues[primitive];
const actual = prim;
const expected = prim;

View File

@@ -34,6 +34,8 @@ function main({ n, len, method, strict }) {
const array = Array(len).fill(1);
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => `str_${i}`);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);

View File

@@ -20,6 +20,8 @@ const bench = common.createBenchmark(main, {
});
function main({ type, n, len, method, strict }) {
if (!method)
method = 'deepEqual';
const clazz = global[type];
const actual = new clazz(len);
const expected = new clazz(len);

View File

@@ -15,6 +15,8 @@ function main({ n, method }) {
const message = 'failure';
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'doesNotThrow':
bench.start();
for (let i = 0; i < n; ++i) {

View File

@@ -17,9 +17,9 @@ const chars = [
function main({ n, len, encoding }) {
let strings = [];
let results = [len * 16];
let results = [ len * 16 ];
if (encoding === 'buffer') {
strings = [Buffer.alloc(len * 16, 'a')];
strings = [ Buffer.alloc(len * 16, 'a') ];
} else {
for (const string of chars) {
// Strings must be built differently, depending on encoding

View File

@@ -16,6 +16,7 @@ const bench = common.createBenchmark(main, {
function main({ len, n, type }) {
let fn, i;
switch (type) {
case '':
case 'fast-alloc':
fn = Buffer.alloc;
break;

View File

@@ -22,7 +22,7 @@ function main({ n, type, size }) {
const buffer = Buffer.allocUnsafe(size);
const testFunction = new Function('b', `
for (var i = 0; i < ${n}; i++) {
b.${type};
b.${type || 'fill(0)'};
}
`);
bench.start();

View File

@@ -21,7 +21,7 @@ function main({ size, type, method, n }) {
Buffer.alloc(size) :
SlowBuffer(size).fill(0);
const fn = methods[method];
const fn = methods[method || 'for'];
bench.start();
fn(buffer, n);

View File

@@ -9,6 +9,7 @@ const bench = common.createBenchmark(main, {
});
function main({ n, type, endian, value }) {
type = type || 'Double';
const buff = Buffer.alloc(8);
const fn = `read${type}${endian}`;
const values = {

View File

@@ -19,7 +19,7 @@ function main({ n, buf, type, byteLength }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
const fn = `read${type}`;
const fn = `read${type || 'IntBE'}`;
buff.writeDoubleLE(0, 0);
bench.start();

View File

@@ -28,7 +28,7 @@ function main({ n, buf, type }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
const fn = `read${type}`;
const fn = `read${type || 'UInt8'}`;
buff.writeDoubleLE(0, 0);
bench.start();

View File

@@ -76,7 +76,7 @@ function genMethod(method) {
function main({ method, len, n, aligned = 'true' }) {
const buf = createBuffer(len, aligned === 'true');
const bufferSwap = genMethod(method);
const bufferSwap = genMethod(method || 'swap16');
bufferSwap(n, buf);
bench.start();

View File

@@ -74,7 +74,7 @@ function main({ n, buf, type }) {
const buff = buf === 'fast' ?
Buffer.alloc(8) :
require('buffer').SlowBuffer(8);
const fn = `write${type}`;
const fn = `write${type || 'UInt8'}`;
if (!/\d/.test(fn))
benchSpecialInt(buff, fn, n);

View File

@@ -40,6 +40,7 @@ const mod = {
};
function main({ n, type }) {
type = type || 'Uint8';
const ab = new ArrayBuffer(8);
const dv = new DataView(ab, 0, 8);
const le = /LE$/.test(type);

View File

@@ -9,6 +9,9 @@ const bench = common.createBenchmark(main, {
});
function main({ n, len, cipher }) {
// Default cipher for tests.
if (cipher === '')
cipher = 'aes-128-gcm';
const message = Buffer.alloc(len, 'b');
const key = crypto.randomBytes(keylen[cipher]);
const iv = crypto.randomBytes(12);

View File

@@ -3,7 +3,7 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
writes: [500],
cipher: ['AES192', 'AES256'],
cipher: [ 'AES192', 'AES256' ],
type: ['asc', 'utf', 'buf'],
len: [2, 1024, 102400, 1024 * 1024],
api: ['legacy', 'stream']
@@ -12,6 +12,9 @@ const bench = common.createBenchmark(main, {
});
function main({ api, cipher, type, len, writes }) {
// Default cipher for tests.
if (cipher === '')
cipher = 'AES192';
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
console.error('Crypto streams not available until v0.10');
// Use the legacy, just so that we can compare them.
@@ -26,6 +29,7 @@ function main({ api, cipher, type, len, writes }) {
alice.generateKeys();
bob.generateKeys();
const pubEnc = /^v0\.[0-8]/.test(process.version) ? 'binary' : null;
const alice_secret = alice.computeSecret(bob.getPublicKey(), pubEnc, 'hex');
const bob_secret = bob.computeSecret(alice.getPublicKey(), pubEnc, 'hex');

View File

@@ -36,6 +36,8 @@ function runDefaultParams(n) {
function main({ n, method }) {
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'withoutdefaults':
runOldStyleDefaults(n);
break;

View File

@@ -36,6 +36,8 @@ function runSwapDestructured(n) {
function main({ n, method }) {
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'swap':
runSwapManual(n);
break;

View File

@@ -33,6 +33,8 @@ function runDestructured(n) {
function main({ n, method }) {
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'normal':
runNormal(n);
break;

View File

@@ -54,6 +54,8 @@ function main({ n, count, method }) {
items[i] = i;
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'for':
fn = useFor;
break;

View File

@@ -104,6 +104,8 @@ function runMap(n) {
function main({ n, method }) {
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'object':
runObject(n);
break;

View File

@@ -51,6 +51,8 @@ function runUseArguments(n) {
function main({ n, method }) {
let fn;
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'copy':
fn = runCopyArguments;
break;

View File

@@ -18,6 +18,8 @@ function main({ n, context, count, rest, method }) {
let obj; // eslint-disable-line no-unused-vars
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case '_extend':
bench.start();
for (let i = 0; i < n; i++)

View File

@@ -32,6 +32,8 @@ function main({ n, context, count, rest, method }) {
args[i] = i;
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'apply':
bench.start();
for (let i = 0; i < n; i++)

View File

@@ -23,6 +23,8 @@ function main({ n, mode }) {
let string;
switch (mode) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'multi-concat':
bench.start();
for (let i = 0; i < n; i++)

View File

@@ -18,6 +18,8 @@ function main({ n, size, encoding, mode }) {
let str;
switch (mode) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'Array':
bench.start();
for (let i = 0; i < n; i++)

View File

@@ -34,6 +34,8 @@ function usingPredefined() {
function main({ n, method, args }) {
let fn;
switch (method) {
// '' is a default case for tests
case '':
case 'restAndSpread':
fn = usingRestAndSpread;
break;

View File

@@ -10,6 +10,8 @@ const bench = common.createBenchmark(main, {
});
function main({ n, type }) {
// Default value for testing purposes.
type = type || 'ascii';
const { getStringWidth } = require('internal/util/inspect');
const str = ({

View File

@@ -64,6 +64,8 @@ function runSymbol(n) {
function main({ n, method }) {
switch (method) {
// '' is a default case for tests
case '':
case 'property':
runProperty(n);
break;

View File

@@ -62,6 +62,8 @@ function runICU(n, val) {
function main({ n, val, method }) {
switch (method) {
// '' is a default case for tests
case '':
case 'punycode':
runPunycode(n, val);
break;

View File

@@ -41,6 +41,7 @@ function main({ n, method }) {
} = common.binding('trace_events');
switch (method) {
case '':
case 'trace':
doTrace(n, trace);
break;

View File

@@ -9,6 +9,10 @@ const bench = common.createBenchmark(main, {
});
function main({ n, type }) {
// Default value for tests.
if (type === '')
type = 'extend';
let fn;
if (type === 'extend') {
fn = util._extend;

View File

@@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, {
});
function main({ type, n }) {
const input = inputs[type];
const input = inputs[type] || '';
// Force-optimize url.format() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.

View File

@@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, {
});
function main({ type, n }) {
const input = inputs[type];
const input = inputs[type] || '';
bench.start();
for (let i = 0; i < n; i += 1)

View File

@@ -23,7 +23,8 @@ const bench = common.createBenchmark(main, {
});
function main({ n, type }) {
const [first, second] = inputs[type];
// For testing, if supplied with an empty type, default to string.
const [first, second] = inputs[type || 'string'];
bench.start();
for (let i = 0; i < n; i++) {

View File

@@ -23,6 +23,8 @@ function main({ n, len, type }) {
opts = { showHidden: true };
arr = arr.fill('denseArray');
break;
// For testing, if supplied with an empty type, default to denseArray.
case '':
case 'denseArray':
arr = arr.fill('denseArray');
break;

View File

@@ -35,6 +35,9 @@ const bench = common.createBenchmark(main, {
});
function main({ type, argument, version, n }) {
// For testing, if supplied with an empty type, default to ArrayBufferView.
type = type || 'ArrayBufferView';
const util = common.binding('util');
const types = require('internal/util/types');