2016-12-25 10:58:36 +08:00
|
|
|
'use strict';
|
2017-09-14 09:48:53 +08:00
|
|
|
const common = require('../common.js');
|
|
|
|
const EventEmitter = require('events').EventEmitter;
|
2016-12-25 10:58:36 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const bench = common.createBenchmark(main, { n: [2e7] });
|
2016-12-25 10:58:36 +08:00
|
|
|
|
|
|
|
function main(conf) {
|
2017-09-14 09:48:53 +08:00
|
|
|
const n = conf.n | 0;
|
2016-12-25 10:58:36 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const ee = new EventEmitter();
|
2016-12-25 10:58:36 +08:00
|
|
|
|
|
|
|
function listener() {}
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; i += 1) {
|
2017-09-14 09:48:53 +08:00
|
|
|
const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
|
2017-07-03 17:52:37 +08:00
|
|
|
ee.once(dummy, listener);
|
|
|
|
ee.emit(dummy);
|
2016-12-25 10:58:36 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|