Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4955fd

Browse filesBrowse files
refackrvagg
authored andcommitted
benchmark,test: refactoring
PR-URL: #26119 Refs: #26101 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 38a87d5 commit f4955fd
Copy full SHA for f4955fd

File tree

Expand file treeCollapse file tree

4 files changed

+47
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+47
-41
lines changed
Open diff view settings
Collapse file
+35-26Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const ClientRequest = require('http').ClientRequest;
4+
const { ClientRequest } = require('http');
5+
const assert = require('assert');
6+
57
const types = Object.keys(common.urls)
68
.filter((i) => common.urls[i]
79
.startsWith('http://'));
@@ -15,36 +17,43 @@ const bench = common.createBenchmark(main, {
1517
function noop() {}
1618

1719
function main({ url: type, arg, e }) {
18-
e = +e;
20+
e = Number(e);
1921
const data = common.bakeUrlData(type, e, false, false)
2022
.filter((i) => i.startsWith('http://'));
2123
const len = data.length;
22-
var result;
23-
var i;
24-
if (arg === 'options') {
25-
const options = data.map((i) => ({
26-
path: new URL(i).path, createConnection: noop
27-
}));
28-
bench.start();
29-
for (i = 0; i < len; i++) {
30-
result = new ClientRequest(options[i]);
24+
let result;
25+
switch (arg) {
26+
case 'options': {
27+
const options = data.map((i) => ({
28+
path: new URL(i).path, createConnection: noop
29+
}));
30+
bench.start();
31+
for (let i = 0; i < len; i++) {
32+
result = new ClientRequest(options[i]);
33+
}
34+
bench.end(len);
35+
break;
36+
}
37+
case 'URL': {
38+
const options = data.map((i) => new URL(i));
39+
bench.start();
40+
for (let i = 0; i < len; i++) {
41+
result = new ClientRequest(options[i], { createConnection: noop });
42+
}
43+
bench.end(len);
44+
break;
3145
}
32-
bench.end(len);
33-
} else if (arg === 'URL') {
34-
const options = data.map((i) => new URL(i));
35-
bench.start();
36-
for (i = 0; i < len; i++) {
37-
result = new ClientRequest(options[i], { createConnection: noop });
46+
case 'string': {
47+
bench.start();
48+
for (let i = 0; i < len; i++) {
49+
result = new ClientRequest(data[i], { createConnection: noop });
50+
}
51+
bench.end(len);
52+
break;
3853
}
39-
bench.end(len);
40-
} else if (arg === 'string') {
41-
bench.start();
42-
for (i = 0; i < len; i++) {
43-
result = new ClientRequest(data[i], { createConnection: noop });
54+
default: {
55+
throw new Error(`Unknown arg type ${arg}`);
4456
}
45-
bench.end(len);
46-
} else {
47-
throw new Error(`Unknown arg type ${arg}`);
4857
}
49-
require('assert').ok(result);
58+
assert.ok(result);
5059
}
Collapse file

‎benchmark/http/headers.js‎

Copy file name to clipboardExpand all lines: benchmark/http/headers.js
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ const common = require('../common.js');
44
const http = require('http');
55

66
const bench = common.createBenchmark(main, {
7-
duplicates: [1, 100],
87
n: [10, 1000],
8+
len: [1, 100],
99
});
1010

11-
function main({ duplicates, n }) {
11+
function main({ len, n }) {
1212
const headers = {
1313
'Connection': 'keep-alive',
1414
'Transfer-Encoding': 'chunked',
1515
};
1616

17-
for (var i = 0; i < n / duplicates; i++) {
18-
headers[`foo${i}`] = [];
19-
for (var j = 0; j < duplicates; j++) {
20-
headers[`foo${i}`].push(`some header value ${i}`);
21-
}
17+
const Is = [ ...Array(n / len).keys() ];
18+
const Js = [ ...Array(len).keys() ];
19+
for (const i of Is) {
20+
headers[`foo${i}`] = Js.map(() => `some header value ${i}`);
2221
}
2322

2423
const server = http.createServer((req, res) => {
Collapse file

‎benchmark/http/incoming_headers.js‎

Copy file name to clipboardExpand all lines: benchmark/http/incoming_headers.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const http = require('http');
55
const bench = common.createBenchmark(main, {
66
// unicode confuses ab on os x.
77
c: [50, 500],
8-
headerDuplicates: [0, 5, 20]
8+
n: [0, 5, 20]
99
});
1010

11-
function main({ c, headerDuplicates }) {
11+
function main({ c, n }) {
1212
const server = http.createServer((req, res) => {
1313
res.end();
1414
});
@@ -21,7 +21,7 @@ function main({ c, headerDuplicates }) {
2121
'Date': new Date().toString(),
2222
'Cache-Control': 'no-cache'
2323
};
24-
for (let i = 0; i < headerDuplicates; i++) {
24+
for (let i = 0; i < n; i++) {
2525
headers[`foo${i}`] = `some header value ${i}`;
2626
}
2727
bench.http({
Collapse file

‎test/benchmark/test-benchmark-http.js‎

Copy file name to clipboardExpand all lines: test/benchmark/test-benchmark-http.js
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ const runBenchmark = require('../common/benchmark');
1414
runBenchmark('http',
1515
[
1616
'benchmarker=test-double-http',
17-
'c=1',
18-
'e=0',
19-
'url=long',
2017
'arg=string',
18+
'c=1',
2119
'chunkedEnc=true',
2220
'chunks=0',
2321
'dur=0.1',
24-
'duplicates=1',
22+
'e=0',
2523
'input=keep-alive',
2624
'key=""',
2725
'len=1',
2826
'method=write',
2927
'n=1',
3028
'res=normal',
3129
'type=asc',
30+
'url=long',
3231
'value=X-Powered-By',
33-
'headerDuplicates=1',
3432
],
3533
{
3634
NODEJS_BENCHMARK_ZERO_ALLOWED: 1,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.