• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const EventEmitter = require('events').EventEmitter;
4
5const bench = common.createBenchmark(main, {
6  n: [2e6],
7  argc: [0, 2, 4, 10],
8  listeners: [1, 5, 10],
9});
10
11function main({ n, argc, listeners }) {
12  const ee = new EventEmitter();
13  ee.setMaxListeners(listeners + 1);
14
15  for (let k = 0; k < listeners; k += 1)
16    ee.on('dummy', () => {});
17
18  switch (argc) {
19    case 2:
20      bench.start();
21      for (let i = 0; i < n; i += 1) {
22        ee.emit('dummy', true, 5);
23      }
24      bench.end(n);
25      break;
26    case 4:
27      bench.start();
28      for (let i = 0; i < n; i += 1) {
29        ee.emit('dummy', true, 5, 10, false);
30      }
31      bench.end(n);
32      break;
33    case 10:
34      bench.start();
35      for (let i = 0; i < n; i += 1) {
36        ee.emit('dummy', true, 5, 10, false, 5, 'string', true, false, 11, 20);
37      }
38      bench.end(n);
39      break;
40    default:
41      bench.start();
42      for (let i = 0; i < n; i += 1) {
43        ee.emit('dummy');
44      }
45      bench.end(n);
46      break;
47  }
48}
49