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