Created
February 27, 2023 20:22
-
-
Save almeidx/79144d794a42e3a5beb5adef0db616a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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