Skip to content

Instantly share code, notes, and snippets.

@almeidx
Created February 27, 2023 20:22
Show Gist options
  • Save almeidx/79144d794a42e3a5beb5adef0db616a9 to your computer and use it in GitHub Desktop.
Save almeidx/79144d794a42e3a5beb5adef0db616a9 to your computer and use it in GitHub Desktop.
import { EventEmitter } from "node:events";
import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter";
import benchmark from "benchmark";
import { EventEmitter as EventEmitter3 } from "eventemitter3";
import { Evt } from "evt";
const suite = new benchmark.Suite();
function handle(a) {}
const ee1 = new EventEmitter();
const aee = new AsyncEventEmitter();
const ee3 = new EventEmitter3();
const evt = new Evt();
aee.on("a", handle);
ee1.on("a", handle);
ee3.on("a", handle);
evt.attach(handle);
suite
.add("node:events", () => {
ee1.emit("a", "b");
})
.add("@vladfrangu/async_event_emitter", () => {
aee.emit("a", "b");
})
.add("eventemitter3", () => {
ee3.emit("a", "b");
})
.add("evt", () => {
evt.post("b");
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function complete() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment