ORM-Benchmark is an Android application built in Android Studio that benchmarks the following against each other:
- Android Raw SQLite
- Android SQLite API Optimization
- ORMLite
- GreenDAO v2 & v3
- Room Persistence Library
The benchmark runs the following tasks:
- CREATE_TABLE - Creation of database structure
- WRITE_DATA - Writing 1000 'user' objects and 10000 'message' objects
- READ_DATA - Read all 10000 'message' objects in the table
- READ_INDEXED - Read an indexed field (the 5000th 'message' in the table)
- READ_SEARCH - Query the first 100 rows that matches a search term (using LIKE)
- DROP_TABLE - Drop database strucuture
Each task is run 50 times, and the application reports the average time for each in milliseconds.
Building and running the ORM-Benchmark project produces output similar to that below.
- The times are in milliseconds.
- The results are shown on the device and are also logged to Logcat.
The results below combine the in-memory database results with the on disk database results side by side. They are from a HUAWEI Mate 10 Android 8.0.
The query results of GreenDao may be slower than your testing. It is the normal phenomenon becuase I had cleared all objects cache in the end of every test case. If the objects cache did not be cleared, the speed can be about 2 to 3 times faster than the results showing in the charts. However, this improvement will be lower as the size of data being larger becuase of the memory limitation.
After pressing "Run Benchmark" you can press "Show Results" to see the results:
- Enable/disable the usage of in-memory SQLite databases. Check MainActivity#USE_IN_MEMORY_DB
- Number of times to run the tests. Check MainActivity#NUM_ITERATIONS
- Implementing your own BenchmarkExecutable you can add more tests.
- Search term. Check BenchmarkExecutable#SEARCH_TERM
- Search limit. Check BenchmarkExecutable#SEARCH_LIMIT
- Number of users to be saved into the db. Check BenchmarkExecutable#NUM_USER_INSERTS
- Number of messages to be saved into the db. Check BenchmarkExecutable#NUM_MESSAGE_INSERTS
- Number of messages with readers. Check BenchmarkExecutable#NUM_MESSAGES_WITH_READERS
- Number of reades on messages. Check BenchmarkExecutable#NUM_READERS
GreenDao v2 requires a separate project to generate the source code for database entities and DAOs. The ORM-Benchmark-GreenDAO-Generator project is a Java application that you can run to regenerate the database definitions. You only need to do this if you want to change the GreenDao database model!