test: add benchmark tests for es
Added parallel test benchmark for es PR-URL: https://github.com/nodejs/node/pull/16076 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
edebc902cf
commit
af49e58211
@ -42,6 +42,8 @@ function main(conf) {
|
|||||||
const n = +conf.millions * 1e6;
|
const n = +conf.millions * 1e6;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'withoutdefaults':
|
case 'withoutdefaults':
|
||||||
runOldStyleDefaults(n);
|
runOldStyleDefaults(n);
|
||||||
break;
|
break;
|
||||||
|
@ -38,6 +38,8 @@ function main(conf) {
|
|||||||
const n = +conf.millions * 1e6;
|
const n = +conf.millions * 1e6;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'swap':
|
case 'swap':
|
||||||
runSwapManual(n);
|
runSwapManual(n);
|
||||||
break;
|
break;
|
||||||
|
@ -37,6 +37,8 @@ function main(conf) {
|
|||||||
const n = +conf.millions * 1e6;
|
const n = +conf.millions * 1e6;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'normal':
|
case 'normal':
|
||||||
runNormal(n);
|
runNormal(n);
|
||||||
break;
|
break;
|
||||||
|
@ -63,6 +63,8 @@ function main(conf) {
|
|||||||
items[i] = i;
|
items[i] = i;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'for':
|
case 'for':
|
||||||
fn = useFor;
|
fn = useFor;
|
||||||
break;
|
break;
|
||||||
|
@ -112,6 +112,8 @@ function main(conf) {
|
|||||||
const n = +conf.millions * 1e6;
|
const n = +conf.millions * 1e6;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'object':
|
case 'object':
|
||||||
runObject(n);
|
runObject(n);
|
||||||
break;
|
break;
|
||||||
|
@ -64,6 +64,8 @@ function main(conf) {
|
|||||||
const n = +conf.millions * 1e6;
|
const n = +conf.millions * 1e6;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'copy':
|
case 'copy':
|
||||||
runCopyArguments(n);
|
runCopyArguments(n);
|
||||||
break;
|
break;
|
||||||
|
@ -33,6 +33,8 @@ function main(conf) {
|
|||||||
args[i] = i;
|
args[i] = i;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (conf.method) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'apply':
|
case 'apply':
|
||||||
bench.start();
|
bench.start();
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
@ -19,14 +19,15 @@ const bench = common.createBenchmark(main, configs);
|
|||||||
|
|
||||||
function main(conf) {
|
function main(conf) {
|
||||||
const n = +conf.n;
|
const n = +conf.n;
|
||||||
const mode = conf.mode;
|
|
||||||
|
|
||||||
const str = 'abc';
|
const str = 'abc';
|
||||||
const num = 123;
|
const num = 123;
|
||||||
|
|
||||||
let string;
|
let string;
|
||||||
|
|
||||||
switch (mode) {
|
switch (conf.mode) {
|
||||||
|
case '':
|
||||||
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'multi-concat':
|
case 'multi-concat':
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++)
|
for (let i = 0; i < n; i++)
|
||||||
@ -63,6 +64,8 @@ function main(conf) {
|
|||||||
string = `${num}`;
|
string = `${num}`;
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error('Unexpected method');
|
||||||
}
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
@ -19,16 +19,23 @@ function main(conf) {
|
|||||||
|
|
||||||
let str;
|
let str;
|
||||||
|
|
||||||
if (conf.mode === 'Array') {
|
switch (conf.mode) {
|
||||||
bench.start();
|
case '':
|
||||||
for (let i = 0; i < n; i++)
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
str = new Array(size + 1).join(character);
|
case 'Array':
|
||||||
bench.end(n);
|
bench.start();
|
||||||
} else {
|
for (let i = 0; i < n; i++)
|
||||||
bench.start();
|
str = new Array(size + 1).join(character);
|
||||||
for (let i = 0; i < n; i++)
|
bench.end(n);
|
||||||
str = character.repeat(size);
|
break;
|
||||||
bench.end(n);
|
case 'repeat':
|
||||||
|
bench.start();
|
||||||
|
for (let i = 0; i < n; i++)
|
||||||
|
str = character.repeat(size);
|
||||||
|
bench.end(n);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error('Unexpected method');
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual([...str].length, size);
|
assert.strictEqual([...str].length, size);
|
||||||
|
18
test/parallel/test-benchmark-es.js
Normal file
18
test/parallel/test-benchmark-es.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('../common');
|
||||||
|
|
||||||
|
const runBenchmark = require('../common/benchmark');
|
||||||
|
|
||||||
|
runBenchmark('es',
|
||||||
|
[
|
||||||
|
'method=',
|
||||||
|
'millions=0.000001',
|
||||||
|
'count=1',
|
||||||
|
'context=null',
|
||||||
|
'rest=0',
|
||||||
|
'mode=',
|
||||||
|
'n=1',
|
||||||
|
'encoding=ascii',
|
||||||
|
'size=1e1'
|
||||||
|
]);
|
Loading…
x
Reference in New Issue
Block a user