GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — benchmark: support URL inputs in create-clientrequest · nodejs/node@ef63bb2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/http
    • create-clientrequest.js
  • test/benchmark
    • test-benchmark-http.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/http/create-clientrequest.js‎

Copy file name to clipboardExpand all lines: benchmark/http/create-clientrequest.js
+40-10Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,49 @@
22

33
const common = require('../common.js');
44
const ClientRequest = require('http').ClientRequest;
5-
5+
const types = Object.keys(common.urls)
6+
.filter((i) => common.urls[i]
7+
.startsWith('http://'));
68
const bench = common.createBenchmark(main, {
7-
len: [1, 8, 16, 32, 64, 128],
8-
n: [1e6]
9+
// Use 'url' to avoid name clash with other http benchmark
10+
url: types.concat(['wpt']),
11+
arg: ['URL', 'string', 'options'],
12+
e: [1]
913
});
1014

11-
function main({ len, n }) {
12-
const path = '/'.repeat(len);
13-
const opts = { path: path, createConnection: function() {} };
15+
function noop() {}
1416

15-
bench.start();
16-
for (var i = 0; i < n; i++) {
17-
new ClientRequest(opts);
17+
function main({ url: type, arg, e }) {
18+
e = +e;
19+
const data = common.bakeUrlData(type, e, false, false)
20+
.filter((i) => i.startsWith('http://'));
21+
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]);
31+
}
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 });
38+
}
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 });
44+
}
45+
bench.end(len);
46+
} else {
47+
throw new Error(`Unknown arg type ${arg}`);
1848
}
19-
bench.end(n);
49+
require('assert').ok(result);
2050
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/benchmark/test-benchmark-http.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ runBenchmark('http',
1515
[
1616
'benchmarker=test-double-http',
1717
'c=1',
18+
'e=0',
19+
'url=long',
20+
'arg=string',
1821
'chunkedEnc=true',
1922
'chunks=0',
2023
'dur=0.1',

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.