11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common.js');
41cb0ef41Sopenharmony_ciconst { ClientRequest } = require('http');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst types = Object.keys(common.urls)
81cb0ef41Sopenharmony_ci  .filter((i) => common.urls[i]
91cb0ef41Sopenharmony_ci  .startsWith('http://'));
101cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
111cb0ef41Sopenharmony_ci  // Use 'url' to avoid name clash with other http benchmark
121cb0ef41Sopenharmony_ci  url: types.concat(['wpt']),
131cb0ef41Sopenharmony_ci  arg: ['URL', 'string', 'options'],
141cb0ef41Sopenharmony_ci  e: [1],
151cb0ef41Sopenharmony_ci});
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifunction noop() {}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction main({ url: type, arg, e }) {
201cb0ef41Sopenharmony_ci  e = Number(e);
211cb0ef41Sopenharmony_ci  const data = common.bakeUrlData(type, e, false, false)
221cb0ef41Sopenharmony_ci    .filter((i) => i.startsWith('http://'));
231cb0ef41Sopenharmony_ci  const len = data.length;
241cb0ef41Sopenharmony_ci  let result;
251cb0ef41Sopenharmony_ci  switch (arg) {
261cb0ef41Sopenharmony_ci    case 'options': {
271cb0ef41Sopenharmony_ci      const options = data.map((i) => ({
281cb0ef41Sopenharmony_ci        path: new URL(i).path, createConnection: noop,
291cb0ef41Sopenharmony_ci      }));
301cb0ef41Sopenharmony_ci      bench.start();
311cb0ef41Sopenharmony_ci      for (let i = 0; i < len; i++) {
321cb0ef41Sopenharmony_ci        result = new ClientRequest(options[i]);
331cb0ef41Sopenharmony_ci      }
341cb0ef41Sopenharmony_ci      bench.end(len);
351cb0ef41Sopenharmony_ci      break;
361cb0ef41Sopenharmony_ci    }
371cb0ef41Sopenharmony_ci    case 'URL': {
381cb0ef41Sopenharmony_ci      const options = data.map((i) => new URL(i));
391cb0ef41Sopenharmony_ci      bench.start();
401cb0ef41Sopenharmony_ci      for (let i = 0; i < len; i++) {
411cb0ef41Sopenharmony_ci        result = new ClientRequest(options[i], { createConnection: noop });
421cb0ef41Sopenharmony_ci      }
431cb0ef41Sopenharmony_ci      bench.end(len);
441cb0ef41Sopenharmony_ci      break;
451cb0ef41Sopenharmony_ci    }
461cb0ef41Sopenharmony_ci    case 'string': {
471cb0ef41Sopenharmony_ci      bench.start();
481cb0ef41Sopenharmony_ci      for (let i = 0; i < len; i++) {
491cb0ef41Sopenharmony_ci        result = new ClientRequest(data[i], { createConnection: noop });
501cb0ef41Sopenharmony_ci      }
511cb0ef41Sopenharmony_ci      bench.end(len);
521cb0ef41Sopenharmony_ci      break;
531cb0ef41Sopenharmony_ci    }
541cb0ef41Sopenharmony_ci    default: {
551cb0ef41Sopenharmony_ci      throw new Error(`Unknown arg type ${arg}`);
561cb0ef41Sopenharmony_ci    }
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci  assert.ok(result);
591cb0ef41Sopenharmony_ci}
60