Skip to content

Commit f30374c

Browse files
committed
Initial commit
0 parents  commit f30374c

31 files changed

+991
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target/
2+
.project
3+
.classpath
4+
.settings/
5+
.idea/
6+
*.iml

jmh.out

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Benchmark Mode Samples Score Score error Units
2+
c.j.b.MapperBenchmark.dozer thrpt 4 99208,765 30696,061 ops/s
3+
c.j.b.MapperBenchmark.manual thrpt 4 15884795,954 1226236,254 ops/s
4+
c.j.b.MapperBenchmark.mapStruct thrpt 4 13639924,895 1656543,383 ops/s
5+
c.j.b.MapperBenchmark.modelMapper thrpt 4 292774,400 61034,248 ops/s
6+
c.j.b.MapperBenchmark.orika thrpt 4 1253002,522 244669,569 ops/s
7+
c.j.b.MapperBenchmark.selma thrpt 4 14903729,450 1160859,245 ops/s

model.png

156 KB
Loading

model.uml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Diagram>
3+
<ID>JAVA</ID>
4+
<OriginalElement />
5+
<nodes>
6+
<node x="363.0" y="102.0">com.javaetmoi.benchmark.mapping.model.dto.OrderDTO</node>
7+
<node x="15.5" y="0.0">com.javaetmoi.benchmark.mapping.model.entity.Address</node>
8+
<node x="0.0" y="124.0">com.javaetmoi.benchmark.mapping.model.entity.Customer</node>
9+
<node x="70.0" y="270.0">com.javaetmoi.benchmark.mapping.model.entity.Order</node>
10+
<node x="189.0" y="146.0">com.javaetmoi.benchmark.mapping.model.entity.Product</node>
11+
<node x="443.5" y="0.0">com.javaetmoi.benchmark.mapping.model.dto.ProductDTO</node>
12+
</nodes>
13+
<notes />
14+
<edges>
15+
<edge source="com.javaetmoi.benchmark.mapping.model.dto.OrderDTO" target="com.javaetmoi.benchmark.mapping.model.dto.ProductDTO">
16+
<point x="0.0" y="-81.0" />
17+
<point x="0.0" y="26.0" />
18+
</edge>
19+
<edge source="com.javaetmoi.benchmark.mapping.model.entity.Customer" target="com.javaetmoi.benchmark.mapping.model.entity.Address">
20+
<point x="0.0" y="-48.0" />
21+
<point x="0.0" y="37.0" />
22+
</edge>
23+
<edge source="com.javaetmoi.benchmark.mapping.model.entity.Order" target="com.javaetmoi.benchmark.mapping.model.entity.Customer">
24+
<point x="-49.5" y="-37.0" />
25+
<point x="119.5" y="245.0" />
26+
<point x="84.5" y="245.0" />
27+
<point x="0.0" y="48.0" />
28+
</edge>
29+
<edge source="com.javaetmoi.benchmark.mapping.model.entity.Order" target="com.javaetmoi.benchmark.mapping.model.entity.Product">
30+
<point x="49.5" y="-37.0" />
31+
<point x="218.5" y="245.0" />
32+
<point x="253.5" y="245.0" />
33+
<point x="0.0" y="26.0" />
34+
</edge>
35+
</edges>
36+
<settings layout="Hierarchic Group" zoom="1.0" x="326.5" y="172.0" />
37+
<SelectedNodes />
38+
<Categories>
39+
<Category>Properties</Category>
40+
</Categories>
41+
<SCOPE>All</SCOPE>
42+
<VISIBILITY>private</VISIBILITY>
43+
</Diagram>
44+

pom.xml

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.javaetmoi.benchmark</groupId>
6+
<artifactId>java-object-mapper-benchmark</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>JMH benchmark of Object-to-Object mapping frameworks/</name>
11+
12+
<prerequisites>
13+
<maven>3.0</maven>
14+
</prerequisites>
15+
16+
<properties>
17+
<version.orkika>1.1.6</version.orkika>
18+
<version.dozer>5.3.2</version.dozer>
19+
<version.modelmapper>0.7.5</version.modelmapper>
20+
<version.mapstruct>1.0.0.CR2</version.mapstruct>
21+
<version.selma>0.12</version.selma>
22+
<version.jmh>1.0</version.jmh>
23+
<version.junit>4.12</version.junit>
24+
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
<javac.target>1.6</javac.target>
27+
<uberjar.name>benchmarks</uberjar.name>
28+
</properties>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.openjdk.jmh</groupId>
33+
<artifactId>jmh-core</artifactId>
34+
<version>${version.jmh}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.openjdk.jmh</groupId>
38+
<artifactId>jmh-generator-annprocess</artifactId>
39+
<version>${version.jmh}</version>
40+
<scope>provided</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>ma.glasnost.orika</groupId>
45+
<artifactId>orika-core</artifactId>
46+
<version>${version.orkika}</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>net.sf.dozer</groupId>
51+
<artifactId>dozer</artifactId>
52+
<version>${version.dozer}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.modelmapper</groupId>
57+
<artifactId>modelmapper</artifactId>
58+
<version>${version.modelmapper}</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.mapstruct</groupId>
63+
<artifactId>mapstruct</artifactId>
64+
<version>${version.mapstruct}</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>fr.xebia.extras</groupId>
69+
<artifactId>selma</artifactId>
70+
<version>${version.selma}</version>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>junit</groupId>
75+
<artifactId>junit</artifactId>
76+
<version>${version.junit}</version>
77+
<scope>test</scope>
78+
</dependency>
79+
</dependencies>
80+
81+
<build>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-compiler-plugin</artifactId>
86+
<version>3.1</version>
87+
<configuration>
88+
<compilerVersion>${javac.target}</compilerVersion>
89+
<source>${javac.target}</source>
90+
<target>${javac.target}</target>
91+
</configuration>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-shade-plugin</artifactId>
96+
<version>2.2</version>
97+
<executions>
98+
<execution>
99+
<phase>package</phase>
100+
<goals>
101+
<goal>shade</goal>
102+
</goals>
103+
<configuration>
104+
<finalName>${uberjar.name}</finalName>
105+
<transformers>
106+
<transformer
107+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
108+
<mainClass>org.openjdk.jmh.Main</mainClass>
109+
</transformer>
110+
</transformers>
111+
</configuration>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
116+
<plugin>
117+
<groupId>org.bsc.maven</groupId>
118+
<artifactId>maven-processor-plugin</artifactId>
119+
<version>2.2.3</version>
120+
<configuration>
121+
<defaultOutputDirectory>
122+
${project.build.directory}/generated-sources
123+
</defaultOutputDirectory>
124+
<processors>
125+
<processor>org.mapstruct.ap.MappingProcessor</processor>
126+
<processor>fr.xebia.extras.selma.codegen.MapperProcessor</processor>
127+
</processors>
128+
</configuration>
129+
<executions>
130+
<execution>
131+
<id>process</id>
132+
<phase>generate-sources</phase>
133+
<goals>
134+
<goal>process</goal>
135+
</goals>
136+
</execution>
137+
</executions>
138+
<dependencies>
139+
<dependency>
140+
<groupId>org.mapstruct</groupId>
141+
<artifactId>mapstruct-processor</artifactId>
142+
<version>${version.mapstruct}</version>
143+
</dependency>
144+
<dependency>
145+
<groupId>fr.xebia.extras</groupId>
146+
<artifactId>selma-processor</artifactId>
147+
<version>${version.selma}</version>
148+
</dependency>
149+
</dependencies>
150+
</plugin>
151+
</plugins>
152+
<pluginManagement>
153+
<plugins>
154+
<plugin>
155+
<artifactId>maven-clean-plugin</artifactId>
156+
<version>2.5</version>
157+
</plugin>
158+
<plugin>
159+
<artifactId>maven-deploy-plugin</artifactId>
160+
<version>2.8.1</version>
161+
</plugin>
162+
<plugin>
163+
<artifactId>maven-install-plugin</artifactId>
164+
<version>2.5.1</version>
165+
</plugin>
166+
<plugin>
167+
<artifactId>maven-jar-plugin</artifactId>
168+
<version>2.4</version>
169+
</plugin>
170+
<plugin>
171+
<artifactId>maven-javadoc-plugin</artifactId>
172+
<version>2.9.1</version>
173+
</plugin>
174+
<plugin>
175+
<artifactId>maven-resources-plugin</artifactId>
176+
<version>2.6</version>
177+
</plugin>
178+
<plugin>
179+
<artifactId>maven-site-plugin</artifactId>
180+
<version>3.3</version>
181+
</plugin>
182+
<plugin>
183+
<artifactId>maven-source-plugin</artifactId>
184+
<version>2.2.1</version>
185+
</plugin>
186+
<plugin>
187+
<artifactId>maven-surefire-plugin</artifactId>
188+
<version>2.17</version>
189+
</plugin>
190+
</plugins>
191+
</pluginManagement>
192+
</build>
193+
194+
</project>

readme.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Object-to-object mapping framework microbenchmark #
2+
3+
Multi-layered applications often require to map between different object models (e.g. DTOs and entities).
4+
Writing such boiler plate mapping code is a tedious and error-prone task.
5+
A lot of object-to-object mapping Java frameworks aims to simplify this work and automate it.
6+
Some uses code instrospection (eg. Dozer). Other uses code generation (ex: MapStuct).
7+
This micro-benchmark compares performance of 5 frameworks. Results could be compared to the benchmark of a code written manually.
8+
9+
Benchmark are powered by a tool called [JMH](http://openjdk.java.net/projects/code-tools/jmh/) or also known as "Java Microbenchmarking Harness".
10+
JMH is developed by the OpenJDK team.
11+
12+
## Benchmarked object to object mapper frameworks ##
13+
14+
- [Dozer](https://github.com/DozerMapper/dozer)
15+
- [MapStruct](http://mapstruct.org/)
16+
- [ModelMapper](http://modelmapper.org/)
17+
- [Selma](http://www.selma-java.org/)
18+
- [Orika](https://github.com/orika-mapper/orika)
19+
20+
## Contributing to benchmark ##
21+
22+
23+
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](http://help.github.com/forking/). If you want to contribute code this way, please reference a GitHub ticket as well covering the specific issue you are addressing.
24+
25+
26+
## Data model ##
27+
28+
The data model used by this benchmark is very basic. It comes from the [Comparison](https://github.com/jhalterman/modelmapper/blob/master/core/src/test/java/org/modelmapper/performance/Comparison.java) class from the ModelMapper framework.
29+
It includes combinations which usually appear in Java Beans, such as:
30+
31+
* Object types
32+
* Collections
33+
34+
35+
## Launch the benchmark ##
36+
37+
_Pre-requisites: Maven 3.x and a JDK 6 (or above)_
38+
39+
``git clone git://github.com/arey/java-object-mapper-benchmark.git``
40+
41+
``mvn clean install``
42+
43+
``java -jar target/benchmarks.jar``
44+
45+
## Results ##
46+
47+
Tests has been performed on:
48+
49+
* OS: MacOSX
50+
* CPU: Core i7 2.8GHz 6MB cache × 4 cores
51+
* RAM: 16GB
52+
* JVM: Oracle 1.8.0_25 64 bits
53+
54+
<table>
55+
<tr>
56+
<th>Benchmark</th><th>Mode</th><th>Samples</th><th>Score</th><th>Margin error (+/-)</th><th>Units</th>
57+
</tr>
58+
<tr>
59+
<th>Manual</th><td>thrpt</td><td>200</td><td>15602264,077</td><td>176798,794</td><td>ops/s</td>
60+
</tr>
61+
<tr>
62+
<th>Selma</th><td>thrpt</td><td>200</td><td>15108316,124</td><td>223022,246</td><td>ops/s</td>
63+
</tr>
64+
<tr>
65+
<th>MapStruct</th><td>thrpt</td><td>200</td><td>13964817,329</td><td>154926,906</td><td>ops/s</td>
66+
</tr>
67+
<tr>
68+
<th>Orika</th><td>thrpt</td><td>200</td><td>1356290,897</td><td>4497,700</td><td>ops/s</td>
69+
</tr>
70+
<tr>
71+
<th>ModelMaper</th><td>thrpt</td><td>200</td><td>278718,964</td><td>2328,241</td><td>ops/s</td>
72+
</tr>
73+
<tr>
74+
<th>Dozer</th><td>thrpt</td><td>200</td><td>104518,910</td><td>979,080</td><td>ops/s</td>
75+
</tr>
76+
</table>
77+
78+
Legend : Higher score is better
79+
80+
Total time: 00:49:01
81+
82+
83+
## Credits ##
84+
85+
* Uses [Maven](http://maven.apache.org/) as a build tool
86+
* Uses [JMH](http://openjdk.java.net/projects/code-tools/jmh/) for Java Microbenchmarking Harness

0 commit comments

Comments
 (0)