forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-clientrequest.js
More file actions
50 lines (47 loc) · 1.34 KB
/
create-clientrequest.js
File metadata and controls
50 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const common = require('../common.js');
const ClientRequest = require('http').ClientRequest;
const types = Object.keys(common.urls)
.filter((i) => common.urls[i]
.startsWith('http://'));
const bench = common.createBenchmark(main, {
// Use 'url' to avoid name clash with other http benchmark
url: types.concat(['wpt']),
arg: ['URL', 'string', 'options'],
e: [1]
});
function noop() {}
function main({ url: type, arg, e }) {
e = +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]);
}
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 });
}
bench.end(len);
} else if (arg === 'string') {
bench.start();
for (i = 0; i < len; i++) {
result = new ClientRequest(data[i], { createConnection: noop });
}
bench.end(len);
} else {
throw new Error(`Unknown arg type ${arg}`);
}
require('assert').ok(result);
}