|
2 | 2 |
|
3 | 3 | const common = require('../common.js');
|
4 | 4 | const ClientRequest = require('http').ClientRequest;
|
5 |
| - |
| 5 | +const types = Object.keys(common.urls) |
| 6 | + .filter((i) => common.urls[i] |
| 7 | + .startsWith('http://')); |
6 | 8 | 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] |
9 | 13 | });
|
10 | 14 |
|
11 |
| -function main({ len, n }) { |
12 |
| - const path = '/'.repeat(len); |
13 |
| - const opts = { path: path, createConnection: function() {} }; |
| 15 | +function noop() {} |
14 | 16 |
|
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}`); |
18 | 48 | }
|
19 |
| - bench.end(n); |
| 49 | + require('assert').ok(result); |
20 | 50 | }
|
0 commit comments