Sha256: 4fde54af548e9c482861ed19d27beba65d5314c79742cbd24b5c690b30db655e

Contents?: true

Size: 1.63 KB

Versions: 67

Compression:

Stored size: 1.63 KB

Contents

'use strict';

// Benchmark comparing performance of event emit for single listener
// To run it, do following in memoizee package path:
//
// $ npm install eventemitter2 signals
// $ node benchmark/single-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('../');
	return ee().on('test', function () { return arguments; });
}());

native = (function () {
	var ee = require('events');
	return (new ee.EventEmitter()).on('test', function () { return arguments; });
}());

ee2 = (function () {
	var ee = require('eventemitter2');
	return (new ee.EventEmitter2()).on('test', function () { return arguments; });
}());

signals = (function () {
	var Signal = require('signals')
	  , ee = { test: new Signal() };
	ee.test.add(function () { return arguments; });
	return ee;
}());

console.log("Emit for single listener", "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];
});

Version data entries

67 entries across 60 versions & 8 rubygems

Version Path
govuk_publishing_components-16.19.0 node_modules/event-emitter/benchmark/single-on.js
govuk_publishing_components-16.18.0 node_modules/event-emitter/benchmark/single-on.js
govuk_publishing_components-16.17.0 node_modules/event-emitter/benchmark/single-on.js
optimacms-0.4.3 spec/dummy/node_modules/event-emitter/benchmark/single-on.js
optimacms-0.4.2 spec/dummy/node_modules/event-emitter/benchmark/single-on.js
cortex-0.1.3 spec/dummy/node_modules/event-emitter/benchmark/single-on.js
guard-sass-lint-0.1.2 node_modules/event-emitter/benchmark/single-on.js
guard-sass-lint-0.1.1 node_modules/event-emitter/benchmark/single-on.js
lanes-0.8.0 node_modules/event-emitter/benchmark/single-on.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/event-emitter/benchmark/single-on.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/event-emitter/benchmark/single-on.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/event-emitter/benchmark/single-on.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/memoizee/node_modules/event-emitter/benchmark/single-on.js