eventure
v0.4.2
Published
<h1 align="center">Eventure</h1>
Readme
🚀 快速开始
📥 安装
# 使用 bun
bun install eventure
# 或使用 npm/yarn/pnpm
npm install eventure
yarn add eventure
pnpm i eventure🚀 性能测试
Eventure vs EventEmitter3 vs EventEmitter2 vs mitt (每次测轮跑 ×10⁵ 次) 该测试可复现,请查看 tinybench,考虑到小于 5% 的误差在实际应用中完全可以忽略, 我们并不想夸大性能优势,Eventure 的目的是保证功能正确的同时保持第一梯队的性能,EE3 缺乏功能,EE2 混乱且难维护,这便是 Eventure 存在的意义。
| # | Task name | Throughput avg (×10⁵ ops/s) | Throughput med (×10⁵ ops/s) | Latency avg (ns) | Latency med (ns) | Samples | | --- | ------------------------- | --------------------------- | --------------------------- | ------------------- | ------------------- | ------- | | 0 | Eventure — pure sync | 541 ± 2.47% | 564 ± 20 | 19.14 ± 5.85% | 17.73 ± 0.061 | 105 | | 1 | EventEmitter3 — pure sync | 448 ± 2.85% | 466 ± 14 | 23.12 ± 5.84% | 21.46 ± 0.061 | 87 | | 2 | EventEmitter2 — pure sync | 416 ± 4.68% | 447 ± 46 | 25.74 ± 7.84% | 22.39 ± 0.218 | 78 | | 3 | mitt — pure sync | 249 ± 3.42% | 244 ± 22 | 40.83 ± 3.83% | 40.97 ± 0.368 | 50 |
| # | Task name | Throughput avg (×10⁵ ops/s) | Throughput med (×10⁵ ops/s) | Latency avg (ns) | Latency med (ns) | Samples | | --- | --------------------------------- | --------------------------- | --------------------------- | -------------------- | -------------------- | ------- | | 0 | Eventure — async end-to-end | 35 ± 9.43% | 37 ± 3 | 292.66 ± 10.05% | 273.38 ± 2.060 | 10 | | 1 | EventEmitter3 — async end-to-end | 33 ± 9.84% | 35 ± 3 | 306.00 ± 10.63% | 282.48 ± 2.320 | 10 | | 2 | EventEmitter2 — async end-to-end | 35 ± 9.77% | 35 ± 4 | 294.56 ± 10.17% | 288.25 ± 2.905 | 10 | | 3 | mitt — async end-to-end | 27 ± 6.63% | 27 ± 2 | 376.48 ± 7.00% | 368.45 ± 2.496 | 10 |
🧪 示例用法
import { Eventure } from "eventure"
interface MyEvents {
foo: [string]; // 等价于 (arg1: string) => void
bar: [number, number]; // (arg1: number, arg2: number) => void
test: (a: number, b: number) => number
numEvent: (value: number, next: (value: number) => number) => number;
}
const emitter = new Eventure<MyEvents>()
emitter.on("foo", (message) => {
console.log(message)
})
emitter.emit("foo", "你好,世界")更多用法请查看: tests/
🤝 贡献指南
欢迎任何形式的贡献!如果你有改进建议或发现了问题,请提交 Pull Request 🙌。
