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