benchmark,test: refactoring
PR-URL: https://github.com/nodejs/node/pull/26119 Refs: https://github.com/nodejs/node/pull/26101 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
146868c75e
commit
c7b6a22f1a
@ -1,7 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common.js');
|
||||
const ClientRequest = require('http').ClientRequest;
|
||||
const { ClientRequest } = require('http');
|
||||
const assert = require('assert');
|
||||
|
||||
const types = Object.keys(common.urls)
|
||||
.filter((i) => common.urls[i]
|
||||
.startsWith('http://'));
|
||||
@ -15,36 +17,43 @@ const bench = common.createBenchmark(main, {
|
||||
function noop() {}
|
||||
|
||||
function main({ url: type, arg, e }) {
|
||||
e = +e;
|
||||
e = Number(e);
|
||||
const data = common.bakeUrlData(type, e, false, false)
|
||||
.filter((i) => i.startsWith('http://'));
|
||||
const len = data.length;
|
||||
var result;
|
||||
var i;
|
||||
if (arg === 'options') {
|
||||
const options = data.map((i) => ({
|
||||
path: new URL(i).path, createConnection: noop
|
||||
}));
|
||||
bench.start();
|
||||
for (i = 0; i < len; i++) {
|
||||
result = new ClientRequest(options[i]);
|
||||
let result;
|
||||
switch (arg) {
|
||||
case 'options': {
|
||||
const options = data.map((i) => ({
|
||||
path: new URL(i).path, createConnection: noop
|
||||
}));
|
||||
bench.start();
|
||||
for (let i = 0; i < len; i++) {
|
||||
result = new ClientRequest(options[i]);
|
||||
}
|
||||
bench.end(len);
|
||||
break;
|
||||
}
|
||||
bench.end(len);
|
||||
} else if (arg === 'URL') {
|
||||
const options = data.map((i) => new URL(i));
|
||||
bench.start();
|
||||
for (i = 0; i < len; i++) {
|
||||
result = new ClientRequest(options[i], { createConnection: noop });
|
||||
case 'URL': {
|
||||
const options = data.map((i) => new URL(i));
|
||||
bench.start();
|
||||
for (let i = 0; i < len; i++) {
|
||||
result = new ClientRequest(options[i], { createConnection: noop });
|
||||
}
|
||||
bench.end(len);
|
||||
break;
|
||||
}
|
||||
bench.end(len);
|
||||
} else if (arg === 'string') {
|
||||
bench.start();
|
||||
for (i = 0; i < len; i++) {
|
||||
result = new ClientRequest(data[i], { createConnection: noop });
|
||||
case 'string': {
|
||||
bench.start();
|
||||
for (let i = 0; i < len; i++) {
|
||||
result = new ClientRequest(data[i], { createConnection: noop });
|
||||
}
|
||||
bench.end(len);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown arg type ${arg}`);
|
||||
}
|
||||
bench.end(len);
|
||||
} else {
|
||||
throw new Error(`Unknown arg type ${arg}`);
|
||||
}
|
||||
require('assert').ok(result);
|
||||
assert.ok(result);
|
||||
}
|
||||
|
@ -4,21 +4,20 @@ const common = require('../common.js');
|
||||
const http = require('http');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
duplicates: [1, 100],
|
||||
n: [10, 1000],
|
||||
len: [1, 100],
|
||||
});
|
||||
|
||||
function main({ duplicates, n }) {
|
||||
function main({ len, n }) {
|
||||
const headers = {
|
||||
'Connection': 'keep-alive',
|
||||
'Transfer-Encoding': 'chunked',
|
||||
};
|
||||
|
||||
for (var i = 0; i < n / duplicates; i++) {
|
||||
headers[`foo${i}`] = [];
|
||||
for (var j = 0; j < duplicates; j++) {
|
||||
headers[`foo${i}`].push(`some header value ${i}`);
|
||||
}
|
||||
const Is = [ ...Array(n / len).keys() ];
|
||||
const Js = [ ...Array(len).keys() ];
|
||||
for (const i of Is) {
|
||||
headers[`foo${i}`] = Js.map(() => `some header value ${i}`);
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
|
@ -5,10 +5,10 @@ const http = require('http');
|
||||
const bench = common.createBenchmark(main, {
|
||||
// unicode confuses ab on os x.
|
||||
c: [50, 500],
|
||||
headerDuplicates: [0, 5, 20]
|
||||
n: [0, 5, 20]
|
||||
});
|
||||
|
||||
function main({ c, headerDuplicates }) {
|
||||
function main({ c, n }) {
|
||||
const server = http.createServer((req, res) => {
|
||||
res.end();
|
||||
});
|
||||
@ -21,7 +21,7 @@ function main({ c, headerDuplicates }) {
|
||||
'Date': new Date().toString(),
|
||||
'Cache-Control': 'no-cache'
|
||||
};
|
||||
for (let i = 0; i < headerDuplicates; i++) {
|
||||
for (let i = 0; i < n; i++) {
|
||||
headers[`foo${i}`] = `some header value ${i}`;
|
||||
}
|
||||
bench.http({
|
||||
|
@ -14,14 +14,12 @@ const runBenchmark = require('../common/benchmark');
|
||||
runBenchmark('http',
|
||||
[
|
||||
'benchmarker=test-double-http',
|
||||
'c=1',
|
||||
'e=0',
|
||||
'url=long',
|
||||
'arg=string',
|
||||
'c=1',
|
||||
'chunkedEnc=true',
|
||||
'chunks=0',
|
||||
'dur=0.1',
|
||||
'duplicates=1',
|
||||
'e=0',
|
||||
'input=keep-alive',
|
||||
'key=""',
|
||||
'len=1',
|
||||
@ -29,8 +27,8 @@ runBenchmark('http',
|
||||
'n=1',
|
||||
'res=normal',
|
||||
'type=asc',
|
||||
'url=long',
|
||||
'value=X-Powered-By',
|
||||
'headerDuplicates=1',
|
||||
],
|
||||
{
|
||||
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user