Which Java Bean Copy Library Is Fastest? A Comprehensive Benchmark
This article benchmarks popular Java bean‑copy tools—including MapStruct, Selma, mica, CGLIB, Spring BeanUtils, and Hutool—under various scenarios such as simple models, type‑conversion, list mapping, and map‑to‑bean conversion, presenting performance scores, error margins, and functional comparisons to help developers choose the most suitable library.
Introduction
Bean copy is widely used in development to dramatically reduce manual mapping work. This article conducts a stress test of common Bean copy tools to help developers select the most appropriate one. It continues the series started with "cglib bean copy introduction".
Bean Copy Tools
MapStruct (compile‑time generated Mapper implementation)
Selma (compile‑time generated Mapper implementation)
yangtu222 – BeanUtils (first‑time generating copy bytecode)
mica (first‑time generating copy bytecode)
hutool (reflection‑based)
Models
No Type Conversion
<code>/**
* Source user
*/
@Data
public class FormUser {
private Long id;
private String nickName;
private Integer age;
private String phone;
private String email;
private String password;
private Integer gender;
private String avatar;
}
/**
* Target user
*/
@Data
public class ToUser {
private String nickName;
private String phone;
private String email;
private Integer gender;
private String avatar;
}</code>With Type Conversion
<code>/**
* Source user with conversion
*/
@Data
@Accessors(chain = true)
public class FormConvertUser {
private Long id;
private String nickName;
private Integer age;
private String phone;
private String email;
private String password;
private Integer gender;
private String avatar;
@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
private LocalDateTime birthday;
}
/**
* Target user with conversion
*/
@Data
@Accessors(chain = true)
public class ToConvertUser {
private String nickName;
private Integer age;
private String phone;
private String email;
private String password;
private Integer gender;
private String avatar;
private String birthday;
}</code>Bean Copy Benchmark Results
Environment
OS: macOS Mojave
CPU: 2.8 GHz Intel Core i5
RAM: 8 GB 1600 MHz DDR3
JVM: Oracle 1.8.0_201 64‑bit
Simple Model
Benchmark Score Error Units
hutool 1939.092 26.747 ops/ms
spring 3569.035 39.607 ops/ms
cglib 9112.785 560.503 ops/ms
mica 17753.409 393.245 ops/ms
yangtu222 18201.997 119.189 ops/ms
cglibMapper 37679.510 3544.624 ops/ms
mapStruct 50328.045 529.707 ops/ms
selma 200859.561 2370.531 ops/msWith Type Conversion (Date)
Benchmark Score Error Units
mica 1186.375 64.686 ops/ms
mapStruct 1623.478 13.894 ops/ms
selma 160020.595 2570.747 ops/msList Model (100 items)
Benchmark Score Error Units
spring 35.974 0.555 ops/ms
mica 169.066 5.460 ops/msMap to Bean Copy
Benchmark Score Error Units
hutool 1338.551 16.746 ops/ms
mica 13577.056 27.795 ops/msConclusion
The results differ slightly from those of the java‑object‑mapper‑benchmark project. Selma performed better than MapStruct in this test, possibly due to differences in the model definitions.
Feature Comparison
Selma – requires writing a Mapper, does not support Map or Collection mapping, needs manual type conversion, performance: extremely high.
MapStruct – requires a Mapper, no Map/Collection support, supports common types and complex expressions, performance: high.
BeanUtils (yangtu222) – no Mapper needed, no Map support, supports List/Set, manual type conversion, performance: high.
mica – no Mapper needed, supports Map and Collection, uses Spring type conversion, performance: high.
Spring – no Mapper needed, no Map/Collection support, no type conversion, performance: medium.
hutool – no Mapper needed, supports Map, no Collection support, no type conversion, performance: medium.
Open‑Source Recommendations
References
[1]MapStruct – http://mapstruct.org/
[2]Selma – http://www.selma-java.org/
[3]yangtu222 – BeanUtils – https://github.com/yangtu222/BeanUtils
[4]mica – https://github.com/lets-mica/mica
[5]hutool – https://gitee.com/loolly/hutool
[6]java‑object‑mapper‑benchmark – https://github.com/arey/java-object-mapper-benchmark
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.