Browse Source

benchmark: Improve event performance tests.

Currently most of the event tests only test a single event type,
which might let those benchmark take fast-paths (in V8) that aren't
taken in realistic use cases, and thus the benchmarks are not good
proxies of real world uses.

PR-URL: https://github.com/nodejs/node/pull/14052
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
v6
Benedikt Meurer 8 years ago
committed by Matteo Collina
parent
commit
0011eb28cf
  1. 11
      benchmark/events/ee-add-remove.js
  2. 9
      benchmark/events/ee-listener-count-on-prototype.js
  3. 9
      benchmark/events/ee-listeners-many.js
  4. 9
      benchmark/events/ee-listeners.js
  5. 5
      benchmark/events/ee-once.js

11
benchmark/events/ee-add-remove.js

@ -16,10 +16,13 @@ function main(conf) {
bench.start();
for (var i = 0; i < n; i += 1) {
for (k = listeners.length; --k >= 0; /* empty */)
ee.on('dummy', listeners[k]);
for (k = listeners.length; --k >= 0; /* empty */)
ee.removeListener('dummy', listeners[k]);
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
for (k = listeners.length; --k >= 0; /* empty */) {
ee.on(dummy, listeners[k]);
}
for (k = listeners.length; --k >= 0; /* empty */) {
ee.removeListener(dummy, listeners[k]);
}
}
bench.end(n);
}

9
benchmark/events/ee-listener-count-on-prototype.js

@ -9,12 +9,15 @@ function main(conf) {
var ee = new EventEmitter();
for (var k = 0; k < 10; k += 1)
ee.on('dummy', function() {});
for (var k = 0; k < 5; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
}
bench.start();
for (var i = 0; i < n; i += 1) {
ee.listenerCount('dummy');
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
ee.listenerCount(dummy);
}
bench.end(n);
}

9
benchmark/events/ee-listeners-many.js

@ -10,12 +10,15 @@ function main(conf) {
var ee = new EventEmitter();
ee.setMaxListeners(101);
for (var k = 0; k < 100; k += 1)
ee.on('dummy', function() {});
for (var k = 0; k < 50; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
}
bench.start();
for (var i = 0; i < n; i += 1) {
ee.listeners('dummy');
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
ee.listeners(dummy);
}
bench.end(n);
}

9
benchmark/events/ee-listeners.js

@ -9,12 +9,15 @@ function main(conf) {
var ee = new EventEmitter();
for (var k = 0; k < 10; k += 1)
ee.on('dummy', function() {});
for (var k = 0; k < 5; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
}
bench.start();
for (var i = 0; i < n; i += 1) {
ee.listeners('dummy');
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
ee.listeners(dummy);
}
bench.end(n);
}

5
benchmark/events/ee-once.js

@ -13,8 +13,9 @@ function main(conf) {
bench.start();
for (var i = 0; i < n; i += 1) {
ee.once('dummy', listener);
ee.emit('dummy');
var dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
ee.once(dummy, listener);
ee.emit(dummy);
}
bench.end(n);
}

Loading…
Cancel
Save