1'use strict';
2const common = require('../common.js');
3
4const bench = common.createBenchmark(main, {
5  withBase: ['true', 'false'],
6  type: ['wpt'],  // Too many combinations - just use WPT by default
7  e: [1],
8  prop: ['href', 'origin', 'protocol',
9         'username', 'password', 'host', 'hostname', 'port',
10         'pathname', 'search', 'searchParams', 'hash'],
11});
12
13function setAndGet(data, prop) {
14  const len = data.length;
15  let result = data[0][prop];
16  bench.start();
17  for (let i = 0; i < len; ++i) {
18    result = data[i][prop];
19    data[i][prop] = result;
20  }
21  bench.end(len);
22  return result;
23}
24
25function get(data, prop) {
26  const len = data.length;
27  let result = data[0][prop];
28  bench.start();
29  for (let i = 0; i < len; ++i) {
30    result = data[i][prop]; // get
31  }
32  bench.end(len);
33  return result;
34}
35
36function main({ e, type, prop, withBase }) {
37  withBase = withBase === 'true';
38  const data = common.bakeUrlData(type, e, withBase, true);
39  switch (prop) {
40    case 'protocol':
41    case 'username':
42    case 'password':
43    case 'host':
44    case 'hostname':
45    case 'port':
46    case 'pathname':
47    case 'search':
48    case 'hash':
49    case 'href':
50      setAndGet(data, prop);
51      break;
52    case 'origin':
53    case 'searchParams':
54      get(data, prop);
55      break;
56    default:
57      throw new Error('Unknown prop');
58  }
59}
60