11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common.js');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst groupedInputs = {
71cb0ef41Sopenharmony_ci  group_common: ['undefined', 'utf8', 'utf-8', 'base64',
81cb0ef41Sopenharmony_ci                 'binary', 'latin1', 'ucs2'],
91cb0ef41Sopenharmony_ci  group_upper: ['UTF-8', 'UTF8', 'UCS2',
101cb0ef41Sopenharmony_ci                'UTF16LE', 'BASE64', 'UCS2'],
111cb0ef41Sopenharmony_ci  group_uncommon: ['foo'],
121cb0ef41Sopenharmony_ci  group_misc: ['', 'utf16le', 'hex', 'HEX', 'BINARY'],
131cb0ef41Sopenharmony_ci};
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst inputs = [
161cb0ef41Sopenharmony_ci  '', 'utf8', 'utf-8', 'UTF-8', 'UTF8', 'Utf8',
171cb0ef41Sopenharmony_ci  'ucs2', 'UCS2', 'utf16le', 'UTF16LE',
181cb0ef41Sopenharmony_ci  'binary', 'BINARY', 'latin1', 'base64', 'BASE64',
191cb0ef41Sopenharmony_ci  'hex', 'HEX', 'foo', 'undefined',
201cb0ef41Sopenharmony_ci];
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
231cb0ef41Sopenharmony_ci  input: inputs.concat(Object.keys(groupedInputs)),
241cb0ef41Sopenharmony_ci  n: [1e5],
251cb0ef41Sopenharmony_ci}, {
261cb0ef41Sopenharmony_ci  flags: '--expose-internals',
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cifunction getInput(input) {
301cb0ef41Sopenharmony_ci  switch (input) {
311cb0ef41Sopenharmony_ci    case 'group_common':
321cb0ef41Sopenharmony_ci      return groupedInputs.group_common;
331cb0ef41Sopenharmony_ci    case 'group_upper':
341cb0ef41Sopenharmony_ci      return groupedInputs.group_upper;
351cb0ef41Sopenharmony_ci    case 'group_uncommon':
361cb0ef41Sopenharmony_ci      return groupedInputs.group_uncommon;
371cb0ef41Sopenharmony_ci    case 'group_misc':
381cb0ef41Sopenharmony_ci      return groupedInputs.group_misc;
391cb0ef41Sopenharmony_ci    case 'undefined':
401cb0ef41Sopenharmony_ci      return [undefined];
411cb0ef41Sopenharmony_ci    default:
421cb0ef41Sopenharmony_ci      return [input];
431cb0ef41Sopenharmony_ci  }
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_cifunction main({ input, n }) {
471cb0ef41Sopenharmony_ci  const { normalizeEncoding } = require('internal/util');
481cb0ef41Sopenharmony_ci  const inputs = getInput(input);
491cb0ef41Sopenharmony_ci  let noDead = '';
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  bench.start();
521cb0ef41Sopenharmony_ci  for (let i = 0; i < n; ++i) {
531cb0ef41Sopenharmony_ci    for (let j = 0; j < inputs.length; ++j) {
541cb0ef41Sopenharmony_ci      noDead = normalizeEncoding(inputs[j]);
551cb0ef41Sopenharmony_ci    }
561cb0ef41Sopenharmony_ci  }
571cb0ef41Sopenharmony_ci  bench.end(n);
581cb0ef41Sopenharmony_ci  assert.ok(noDead === undefined || noDead.length > 0);
591cb0ef41Sopenharmony_ci}
60