EventBus 和Otto的区别

本文对比了Otto与EventBus在功能和性能上的差异,包括事件处理方法、命名约定、注解使用、事件继承、事件缓存、事件生产者等,并通过Android应用性能基准测试进行了实证分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Otto is another event bus library for Android; actually it’s a fork of Guava’s EventBus. greenrobot’s EventBus and Otto share some basic semantics (register, post, unregister, …), but there are differences which the following table summarizes:

EventBusOtto
Declare event handling methodsName conventionsAnnotations
Event inheritanceYesYes
Subscriber inheritanceYesNo
Cache most recent eventsYes, sticky eventsNo
Event producers (e.g. for coding cached events)NoYes
Event delivery in posting threadYes (Default)Yes
Event delivery in main threadYesNo
Event delivery in background threadYesNo
Aynchronous event deliveryYesNo

Besides features, performance is another differentiator. To compare performance, we created an Android application, which is also part of this repository (EventBusPerformance). You can also run the app on your phone to benchmark different scenarios.

Benchmark results indicate that EventBus is significantly faster in almost every scenario:

EventBusOtto
Posting 1000 events, Android 2.3 emulator~70% faster
Posting 1000 events, S3 Android 4.0~110% faster
Register 1000 subscribers, Android 2.3 emulator~10% faster
Register 1000 subscribers, S3 Android 4.0~70% faster
Register subscribers cold start, Android 2.3 emulator~350% faster
Register subscribers cold start, S3 Android 4.0About the same
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值