1'use strict'; 2 3const common = require('../common.js'); 4const { ClientRequest } = require('http'); 5const assert = require('assert'); 6 7const types = Object.keys(common.urls) 8 .filter((i) => common.urls[i] 9 .startsWith('http://')); 10const bench = common.createBenchmark(main, { 11 // Use 'url' to avoid name clash with other http benchmark 12 url: types.concat(['wpt']), 13 arg: ['URL', 'string', 'options'], 14 e: [1], 15}); 16 17function noop() {} 18 19function main({ url: type, arg, e }) { 20 e = Number(e); 21 const data = common.bakeUrlData(type, e, false, false) 22 .filter((i) => i.startsWith('http://')); 23 const len = data.length; 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; 45 } 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; 53 } 54 default: { 55 throw new Error(`Unknown arg type ${arg}`); 56 } 57 } 58 assert.ok(result); 59} 60