1'use strict'; 2const common = require('../common.js'); 3const events = require('events'); 4 5const bench = common.createBenchmark(main, { n: [1e6] }); 6 7function main({ n }) { 8 const ee = new events.EventEmitter(); 9 const listeners = []; 10 11 for (let k = 0; k < 10; k += 1) 12 listeners.push(() => {}); 13 14 bench.start(); 15 for (let i = 0; i < n; i += 1) { 16 const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1'; 17 for (let k = listeners.length; --k >= 0; /* empty */) { 18 ee.on(dummy, listeners[k]); 19 } 20 for (let k = listeners.length; --k >= 0; /* empty */) { 21 ee.removeListener(dummy, listeners[k]); 22 } 23 } 24 bench.end(n); 25} 26