Multi-layered applications often require to map between different object models (e.g. DTOs and entities). Writing such boiler plate mapping code is a tedious and error-prone task. A lot of object-to-object mapping Java frameworks aims to simplify this work and automate it. Some uses code instrospection (eg. Dozer). Other uses code generation (ex: MapStuct). This micro-benchmark compares performance of 6 frameworks. Results could be compared to the benchmark of a code written manually.
Benchmark are powered by a tool called JMH or also known as "Java Microbenchmarking Harness". JMH is developed by the OpenJDK team.
Github is for social coding platform: if you want to add another mapping framework or optimize an existing one, we encourage contributions through pull requests from forks of this repository. If you want to contribute code this way, please reference a GitHub ticket as well covering the specific issue you are addressing.
The data model used by this benchmark is very basic. It comes from the Comparison class from the ModelMapper framework. It includes combinations which usually appear in Java Beans, such as:
- Object types
- Collections
Pre-requisites: Maven 3.x and a JDK 6 (or above)
git clone git://github.com/arey/java-object-mapper-benchmark.git
mvn clean install
java -jar target/benchmarks.jar
Tests has been performed on:
- OS: OS X El Capitan
- CPU: 3.1 GHz Intel Core i7, 2 cores, L2 Cache (per Core): 256 KB, L3 Cache: 4 MB
- RAM: 16 GB 1867 MHz DDR3
- JVM: Oracle 1.8.0_102 64 bits
Benchmark | Mode | Samples | Score | Margin error (+/-) | Units |
---|---|---|---|---|---|
Manual | thrpt | 200 | 16 449 065 | 53 680 | ops/s |
Selma | thrpt | 200 | 15 806 337 | 41 094 | ops/s |
MapStruct | thrpt | 200 | 14 237 194 | 51 179 | ops/s |
JMapper | thrpt | 200 | 13 960 300 | 58 236 | ops/s |
Orika | thrpt | 200 | 3 014 113 | 14 411 | ops/s |
ModelMaper | thrpt | 200 | 246 365 | 2 019 | ops/s |
Dozer | thrpt | 200 | 78 140 | 349 | ops/s |
Legend : Higher score is better
Total time: 00:48:33
- Micro-benchmark of Java mapping object frameworks (french article)