A few weeks ago we’ve got a little discussion about “Which way should we use to manipulate list or collection?” at the office.
To get the answer I created a tiny sample project to compare each library’s performance.
With above libraries I prepared a simple processing like:
- Put string list(has 20 item) to method
- Fiter them by having a “ok” prefix or not
- Change them to upper case letter
- Return converted list
The actual code is the following.
Actualy I timed each method execution by JUnit(not on the Android device, just on my local macbook with Java8(1.8.0_77).
You can see the test code from here.
And the result and average times(from 5 times execution) are…
- With no libraries…1ms
- When it comes to the performance, using no library is the fastest as we expected, but the code becomes a little bit tedious.
- If we choose one library, It seems like Lightweight-Stream-API is the best selection, since it has a good performance and syantax is just the backport of Java8.
- If there is no specific reason I don’t recommend you to use RxJava and IxJava to deal with this kind of problem. The syantax is sort of tedious and performance is not good either.
You can see my sample from here, so please give me a feedback if you have one.