-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventEmitting.js
47 lines (40 loc) · 1.05 KB
/
eventEmitting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* A naive benchmark testing the performance hit when only using
* events, thus defaulting to regular EventEmitter behaviour.
*/
var Benchmark = require('benchmark');
var EventEmitter = require('events').EventEmitter;
var PatternEmitter = require('../lib/patternEmitter');
var suite = new Benchmark.Suite();
var eventEmitter = new EventEmitter();
var patternEmitter = new PatternEmitter();
var i, j;
// Setup both emitters with 10 listeners on each of 10 events
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
eventEmitter.on('event:' + i, function() {
// Do nothing
});
}
}
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
patternEmitter.on('event:' + i, function() {
// Do nothing
});
}
}
suite.add('EventEmitter', function() {
for (i = 0; i < 10; i++) {
eventEmitter.emit('event:' + i);
}
})
.add('PatternEmitter', function() {
for (i = 0; i < 10; i++) {
patternEmitter.emit('event:' + i);
}
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.run();