https://github.com/dinaraparanid/observabletest
Benchmarking Observables from RxJava (Observable, Flowable, Single) and Kotlin Coroutines (Channels, Flows)
https://github.com/dinaraparanid/observabletest
coroutines kotlin kotlin-coroutines observable observer-pattern rxjava
Last synced: 11 months ago
JSON representation
Benchmarking Observables from RxJava (Observable, Flowable, Single) and Kotlin Coroutines (Channels, Flows)
- Host: GitHub
- URL: https://github.com/dinaraparanid/observabletest
- Owner: dinaraparanid
- License: apache-2.0
- Created: 2023-01-16T12:33:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-17T07:36:19.000Z (over 3 years ago)
- Last Synced: 2025-06-06T05:35:00.626Z (about 1 year ago)
- Topics: coroutines, kotlin, kotlin-coroutines, observable, observer-pattern, rxjava
- Language: Kotlin
- Homepage:
- Size: 3.42 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Observable Test
Next code is the benchmark of all suitable (for the task) observables from both RxJava and Coroutines.
Task is to find all files in given directory (including files in subdirectories) with given "fileName"
in their name (including extension). For all observables, except Single and Flow, I have sent each file
separately from background thread (producer) to main thread (collector). For Single, I have collected all
files in list. For Flow, - everything is the same as with others, but file searching is done in main thread.
Also, I only used one background thread (where it is possible) for file walking
After 10 tries of searching files in folder with 65K files in total (I was searching for all '.xml' files and found 930 of them), I have received next results for each observer:
## RxJava
- Observable: 468 ms
- Flowable: 450.6 ms
- Single: 463 ms
## Coroutines
- Channel: 777,8 ms
- Flow: 397,9 ms
- Shared Flow: 1405 ms
- Broadcast Channel: 623.2 ms
- Callback Flow: 503,3 ms
### Fun facts:
- Surprisingly, BroadcastChannel (that is deprecated now) is far better than its 'successor' SharedFlow.
- All observables from RxJava are mostly on same level of performance, however, Flowable is usually faster.
- Callback Flow is very close to RxJava's observables.
- Flow looks better, because it is suited for a single thread (no synchronization).