benchmark: refactor
PR-URL: https://github.com/nodejs/node/pull/18320 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
c713f079f1
commit
1b6cb94761
@ -22,22 +22,23 @@ function endAfterGC(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main({ n, method }) {
|
function main({ n, method }) {
|
||||||
|
var i;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'trackingEnabled':
|
case 'trackingEnabled':
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
new AsyncResource('foobar');
|
new AsyncResource('foobar');
|
||||||
}
|
}
|
||||||
endAfterGC(n);
|
endAfterGC(n);
|
||||||
break;
|
break;
|
||||||
case 'trackingDisabled':
|
case 'trackingDisabled':
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
new AsyncResource('foobar', { requireManualDestroy: true });
|
new AsyncResource('foobar', { requireManualDestroy: true });
|
||||||
}
|
}
|
||||||
endAfterGC(n);
|
endAfterGC(n);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('Unsupported method');
|
throw new Error(`Unsupported method "${method}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,11 @@ const noop = () => {};
|
|||||||
function main({ n, port, address }) {
|
function main({ n, port, address }) {
|
||||||
port = port === 'true' ? 0 : undefined;
|
port = port === 'true' ? 0 : undefined;
|
||||||
address = address === 'true' ? '0.0.0.0' : undefined;
|
address = address === 'true' ? '0.0.0.0' : undefined;
|
||||||
|
var i;
|
||||||
|
|
||||||
if (port !== undefined && address !== undefined) {
|
if (port !== undefined && address !== undefined) {
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
dgram.createSocket('udp4').bind(port, address)
|
dgram.createSocket('udp4').bind(port, address)
|
||||||
.on('error', noop)
|
.on('error', noop)
|
||||||
.unref();
|
.unref();
|
||||||
@ -26,7 +27,7 @@ function main({ n, port, address }) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
} else if (port !== undefined) {
|
} else if (port !== undefined) {
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
dgram.createSocket('udp4')
|
dgram.createSocket('udp4')
|
||||||
.bind(port)
|
.bind(port)
|
||||||
.on('error', noop)
|
.on('error', noop)
|
||||||
@ -35,7 +36,7 @@ function main({ n, port, address }) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
} else if (port === undefined && address === undefined) {
|
} else if (port === undefined && address === undefined) {
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
dgram.createSocket('udp4')
|
dgram.createSocket('udp4')
|
||||||
.bind()
|
.bind()
|
||||||
.on('error', noop)
|
.on('error', noop)
|
||||||
|
@ -28,15 +28,6 @@ function main({ n, args }) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn(a, b, c) {
|
function fn(a = 1, b = 2, c = 3) {
|
||||||
if (!a)
|
|
||||||
a = 1;
|
|
||||||
|
|
||||||
if (!b)
|
|
||||||
b = 2;
|
|
||||||
|
|
||||||
if (!c)
|
|
||||||
c = 3;
|
|
||||||
|
|
||||||
return a + b + c;
|
return a + b + c;
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,8 @@ function main({ n, pathType }) {
|
|||||||
bench.start();
|
bench.start();
|
||||||
if (pathType === 'relative')
|
if (pathType === 'relative')
|
||||||
relativePath(n);
|
relativePath(n);
|
||||||
else if (pathType === 'resolved')
|
|
||||||
resolvedPath(n);
|
|
||||||
else
|
else
|
||||||
throw new Error(`unknown "pathType": ${pathType}`);
|
resolvedPath(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativePath(n) {
|
function relativePath(n) {
|
||||||
|
@ -15,24 +15,10 @@ const bench = common.createBenchmark(main, {
|
|||||||
|
|
||||||
|
|
||||||
function main({ n, pathType }) {
|
function main({ n, pathType }) {
|
||||||
|
const path = pathType === 'relative' ? relative_path : resolved_path;
|
||||||
bench.start();
|
bench.start();
|
||||||
if (pathType === 'relative')
|
for (var i = 0; i < n; i++) {
|
||||||
relativePath(n);
|
fs.realpathSync(path);
|
||||||
else if (pathType === 'resolved')
|
}
|
||||||
resolvedPath(n);
|
|
||||||
else
|
|
||||||
throw new Error(`unknown "pathType": ${pathType}`);
|
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativePath(n) {
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
fs.realpathSync(relative_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolvedPath(n) {
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
fs.realpathSync(resolved_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -36,7 +36,6 @@ function main({ dur, encodingType, size }) {
|
|||||||
try { fs.unlinkSync(filename); } catch (e) {}
|
try { fs.unlinkSync(filename); } catch (e) {}
|
||||||
|
|
||||||
var started = false;
|
var started = false;
|
||||||
var ending = false;
|
|
||||||
var ended = false;
|
var ended = false;
|
||||||
|
|
||||||
var f = fs.createWriteStream(filename);
|
var f = fs.createWriteStream(filename);
|
||||||
@ -52,15 +51,9 @@ function main({ dur, encodingType, size }) {
|
|||||||
|
|
||||||
|
|
||||||
function write() {
|
function write() {
|
||||||
// don't try to write after we end, even if a 'drain' event comes.
|
|
||||||
// v0.8 streams are so sloppy!
|
|
||||||
if (ending)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!started) {
|
if (!started) {
|
||||||
started = true;
|
started = true;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ending = true;
|
|
||||||
f.end();
|
f.end();
|
||||||
}, dur * 1000);
|
}, dur * 1000);
|
||||||
bench.start();
|
bench.start();
|
||||||
|
@ -12,7 +12,6 @@ function main({ n }) {
|
|||||||
const FreeList = require('internal/freelist');
|
const FreeList = require('internal/freelist');
|
||||||
const poolSize = 1000;
|
const poolSize = 1000;
|
||||||
const list = new FreeList('test', poolSize, Object);
|
const list = new FreeList('test', poolSize, Object);
|
||||||
var i;
|
|
||||||
var j;
|
var j;
|
||||||
const used = [];
|
const used = [];
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ function main({ n }) {
|
|||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
// Return all the items to the pool
|
// Return all the items to the pool
|
||||||
for (j = 0; j < poolSize; j++) {
|
for (j = 0; j < poolSize; j++) {
|
||||||
list.free(used[j]);
|
list.free(used[j]);
|
||||||
|
@ -32,11 +32,9 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ millions, type }) {
|
function main({ millions, type }) {
|
||||||
const n = millions * 1e6;
|
|
||||||
|
|
||||||
const fn = type === 'cxx' ? cxx : js;
|
const fn = type === 'cxx' ? cxx : js;
|
||||||
bench.start();
|
bench.start();
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < millions * 1e6; i++) {
|
||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
bench.end(millions);
|
bench.end(millions);
|
||||||
|
@ -78,6 +78,6 @@ function main({ millions, method }) {
|
|||||||
runSymbol(n);
|
runSymbol(n);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('Unexpected method');
|
throw new Error(`Unexpected method "${method}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,9 +55,8 @@ function runPunycode(n, val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function runICU(n, val) {
|
function runICU(n, val) {
|
||||||
var i = 0;
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; i++)
|
for (var i = 0; i < n; i++)
|
||||||
usingICU(val);
|
usingICU(val);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
@ -76,6 +75,6 @@ function main({ n, val, method }) {
|
|||||||
}
|
}
|
||||||
// fallthrough
|
// fallthrough
|
||||||
default:
|
default:
|
||||||
throw new Error('Unexpected method');
|
throw new Error(`Unexpected method "${method}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,10 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ thousands, fullPath, useCache }) {
|
function main({ thousands, fullPath, useCache }) {
|
||||||
const n = thousands * 1e3;
|
|
||||||
|
|
||||||
tmpdir.refresh();
|
tmpdir.refresh();
|
||||||
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
|
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
|
||||||
|
|
||||||
for (var i = 0; i <= n; i++) {
|
for (var i = 0; i <= thousands * 1e3; i++) {
|
||||||
fs.mkdirSync(`${benchmarkDirectory}${i}`);
|
fs.mkdirSync(`${benchmarkDirectory}${i}`);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`${benchmarkDirectory}${i}/package.json`,
|
`${benchmarkDirectory}${i}/package.json`,
|
||||||
@ -31,37 +29,37 @@ function main({ thousands, fullPath, useCache }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fullPath === 'true')
|
if (fullPath === 'true')
|
||||||
measureFull(n, useCache === 'true');
|
measureFull(thousands, useCache === 'true');
|
||||||
else
|
else
|
||||||
measureDir(n, useCache === 'true');
|
measureDir(thousands, useCache === 'true');
|
||||||
|
|
||||||
tmpdir.refresh();
|
tmpdir.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
function measureFull(n, useCache) {
|
function measureFull(thousands, useCache) {
|
||||||
var i;
|
var i;
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
for (i = 0; i <= n; i++) {
|
for (i = 0; i <= thousands * 1e3; i++) {
|
||||||
require(`${benchmarkDirectory}${i}/index.js`);
|
require(`${benchmarkDirectory}${i}/index.js`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bench.start();
|
bench.start();
|
||||||
for (i = 0; i <= n; i++) {
|
for (i = 0; i <= thousands * 1e3; i++) {
|
||||||
require(`${benchmarkDirectory}${i}/index.js`);
|
require(`${benchmarkDirectory}${i}/index.js`);
|
||||||
}
|
}
|
||||||
bench.end(n / 1e3);
|
bench.end(thousands);
|
||||||
}
|
}
|
||||||
|
|
||||||
function measureDir(n, useCache) {
|
function measureDir(thousands, useCache) {
|
||||||
var i;
|
var i;
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
for (i = 0; i <= n; i++) {
|
for (i = 0; i <= thousands * 1e3; i++) {
|
||||||
require(`${benchmarkDirectory}${i}`);
|
require(`${benchmarkDirectory}${i}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bench.start();
|
bench.start();
|
||||||
for (i = 0; i <= n; i++) {
|
for (i = 0; i <= thousands * 1e3; i++) {
|
||||||
require(`${benchmarkDirectory}${i}`);
|
require(`${benchmarkDirectory}${i}`);
|
||||||
}
|
}
|
||||||
bench.end(n / 1e3);
|
bench.end(thousands);
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,15 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ n }) {
|
function main({ n }) {
|
||||||
var i = 0;
|
const input = ['ABC', 'XYZ123', 'FOO'];
|
||||||
var m = {};
|
var m = {};
|
||||||
// First call dominates results
|
// First call dominates results
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m);
|
tls.convertNPNProtocols(input, m);
|
||||||
m = {};
|
m = {};
|
||||||
}
|
}
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; i++) tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m);
|
for (var i = 0; i < n; i++)
|
||||||
|
tls.convertNPNProtocols(input, m);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,7 @@ const bench = common.createBenchmark(main, {
|
|||||||
|
|
||||||
function main({ n, type }) {
|
function main({ n, type }) {
|
||||||
// For testing, if supplied with an empty type, default to string.
|
// For testing, if supplied with an empty type, default to string.
|
||||||
type = type || 'string';
|
const [first, second] = inputs[type || 'string'];
|
||||||
|
|
||||||
const [first, second] = inputs[type];
|
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
|
@ -18,14 +18,13 @@ function main({ n, len, type }) {
|
|||||||
var arr = Array(len);
|
var arr = Array(len);
|
||||||
var i, opts;
|
var i, opts;
|
||||||
|
|
||||||
// For testing, if supplied with an empty type, default to denseArray.
|
|
||||||
type = type || 'denseArray';
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'denseArray_showHidden':
|
case 'denseArray_showHidden':
|
||||||
opts = { showHidden: true };
|
opts = { showHidden: true };
|
||||||
arr = arr.fill('denseArray');
|
arr = arr.fill('denseArray');
|
||||||
break;
|
break;
|
||||||
|
// For testing, if supplied with an empty type, default to denseArray.
|
||||||
|
case '':
|
||||||
case 'denseArray':
|
case 'denseArray':
|
||||||
arr = arr.fill('denseArray');
|
arr = arr.fill('denseArray');
|
||||||
break;
|
break;
|
||||||
|
@ -12,9 +12,8 @@ const bench = common.createBenchmark(main, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function main({ method, n }) {
|
function main({ method, n }) {
|
||||||
var i = 0;
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; i++)
|
for (var i = 0; i < n; i++)
|
||||||
v8[method]();
|
v8[method]();
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,10 @@ function main({ n, breakOnSigint, withSigintListener }) {
|
|||||||
if (withSigintListener)
|
if (withSigintListener)
|
||||||
process.on('SIGINT', () => {});
|
process.on('SIGINT', () => {});
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
const contextifiedSandbox = vm.createContext();
|
const contextifiedSandbox = vm.createContext();
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; i++)
|
for (var i = 0; i < n; i++)
|
||||||
vm.runInContext('0', contextifiedSandbox, options);
|
vm.runInContext('0', contextifiedSandbox, options);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,8 @@ function main({ n, breakOnSigint, withSigintListener }) {
|
|||||||
if (withSigintListener)
|
if (withSigintListener)
|
||||||
process.on('SIGINT', () => {});
|
process.on('SIGINT', () => {});
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; i++)
|
for (var i = 0; i < n; i++)
|
||||||
vm.runInThisContext('0', options);
|
vm.runInThisContext('0', options);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user