/usr/lib/nodejs/event-emitter/benchmark/many-on.js is in node-event-emitter 0.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | 'use strict';
// Benchmark comparing performance of event emit for many listeners
// To run it, do following in memoizee package path:
//
// $ npm install eventemitter2 signals
// $ node benchmark/many-on.js
var forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')
, now = Date.now
, time, count = 1000000, i, data = {}
, ee, native, ee2, signals, a = {}, b = {};
ee = (function () {
var ee = require('../')();
ee.on('test', function () { return arguments; });
ee.on('test', function () { return arguments; });
return ee.on('test', function () { return arguments; });
}());
native = (function () {
var ee = require('events');
ee = new ee.EventEmitter();
ee.on('test', function () { return arguments; });
ee.on('test', function () { return arguments; });
return ee.on('test', function () { return arguments; });
}());
ee2 = (function () {
var ee = require('eventemitter2');
ee = new ee.EventEmitter2();
ee.on('test', function () { return arguments; });
ee.on('test', function () { return arguments; });
return ee.on('test', function () { return arguments; });
}());
signals = (function () {
var Signal = require('signals')
, ee = { test: new Signal() };
ee.test.add(function () { return arguments; });
ee.test.add(function () { return arguments; });
ee.test.add(function () { return arguments; });
return ee;
}());
console.log("Emit for 3 listeners", "x" + count + ":\n");
i = count;
time = now();
while (i--) {
ee.emit('test', a, b);
}
data["event-emitter (this implementation)"] = now() - time;
i = count;
time = now();
while (i--) {
native.emit('test', a, b);
}
data["EventEmitter (Node.js native)"] = now() - time;
i = count;
time = now();
while (i--) {
ee2.emit('test', a, b);
}
data.EventEmitter2 = now() - time;
i = count;
time = now();
while (i--) {
signals.test.dispatch(a, b);
}
data.Signals = now() - time;
forEach(data, function (value, name, obj, index) {
console.log(index + 1 + ":", pad.call(value, " ", 5), name);
}, null, function (a, b) {
return this[a] - this[b];
});
|