11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common.js');
31cb0ef41Sopenharmony_ciconst EventEmitter = require('events').EventEmitter;
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
61cb0ef41Sopenharmony_ci  n: [2e7],
71cb0ef41Sopenharmony_ci  argc: [0, 1, 4, 5],
81cb0ef41Sopenharmony_ci});
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction main({ n, argc }) {
111cb0ef41Sopenharmony_ci  const ee = new EventEmitter();
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  function listener() {}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  switch (argc) {
161cb0ef41Sopenharmony_ci    case 0:
171cb0ef41Sopenharmony_ci      bench.start();
181cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i += 1) {
191cb0ef41Sopenharmony_ci        const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
201cb0ef41Sopenharmony_ci        ee.once(dummy, listener);
211cb0ef41Sopenharmony_ci        ee.emit(dummy);
221cb0ef41Sopenharmony_ci      }
231cb0ef41Sopenharmony_ci      bench.end(n);
241cb0ef41Sopenharmony_ci      break;
251cb0ef41Sopenharmony_ci    case 1:
261cb0ef41Sopenharmony_ci      bench.start();
271cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i += 1) {
281cb0ef41Sopenharmony_ci        const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
291cb0ef41Sopenharmony_ci        ee.once(dummy, listener);
301cb0ef41Sopenharmony_ci        ee.emit(dummy, n);
311cb0ef41Sopenharmony_ci      }
321cb0ef41Sopenharmony_ci      bench.end(n);
331cb0ef41Sopenharmony_ci      break;
341cb0ef41Sopenharmony_ci    case 4:
351cb0ef41Sopenharmony_ci      bench.start();
361cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i += 1) {
371cb0ef41Sopenharmony_ci        const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
381cb0ef41Sopenharmony_ci        ee.once(dummy, listener);
391cb0ef41Sopenharmony_ci        ee.emit(dummy, 'foo', argc, 'bar', false);
401cb0ef41Sopenharmony_ci      }
411cb0ef41Sopenharmony_ci      bench.end(n);
421cb0ef41Sopenharmony_ci      break;
431cb0ef41Sopenharmony_ci    case 5:
441cb0ef41Sopenharmony_ci      bench.start();
451cb0ef41Sopenharmony_ci      for (let i = 0; i < n; i += 1) {
461cb0ef41Sopenharmony_ci        const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
471cb0ef41Sopenharmony_ci        ee.once(dummy, listener);
481cb0ef41Sopenharmony_ci        ee.emit(dummy, true, 7.5, 'foo', null, n);
491cb0ef41Sopenharmony_ci      }
501cb0ef41Sopenharmony_ci      bench.end(n);
511cb0ef41Sopenharmony_ci      break;
521cb0ef41Sopenharmony_ci    default:
531cb0ef41Sopenharmony_ci      throw new Error('Unsupported argument count');
541cb0ef41Sopenharmony_ci  }
551cb0ef41Sopenharmony_ci}
56