Skip to content

Commit

Permalink
benchmark,test: refactoring
Browse files Browse the repository at this point in the history
PR-URL: #26119
Refs: #26101
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
refack authored and rvagg committed Feb 28, 2019
1 parent 38a87d5 commit f4955fd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
61 changes: 35 additions & 26 deletions benchmark/http/create-clientrequest.js
Original file line number Diff line number Diff line change
@@ -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://'));
Expand All @@ -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;
}
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 === '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 'string': {
bench.start();
for (let i = 0; i < len; i++) {
result = new ClientRequest(data[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 });
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);
}
13 changes: 6 additions & 7 deletions benchmark/http/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/http/incoming_headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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({
Expand Down
8 changes: 3 additions & 5 deletions test/benchmark/test-benchmark-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ 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',
'method=write',
'n=1',
'res=normal',
'type=asc',
'url=long',
'value=X-Powered-By',
'headerDuplicates=1',
],
{
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,
Expand Down

0 comments on commit f4955fd

Please sign in to comment.