Bean Mapping and Performance

https://www.baeldung.com/java-performance-mapping-frameworks

Creating large Java applications composed of multiple layers require using multiple models such as persistence model, domain model or so-called DTOs. Using multiple models for different application layers will require us to provide a way of mapping between beans.
Doing this manually can quickly create much boilerplate code and consume a lot of time. Luckily for us, there are multiple object mapping frameworks for Java.

  1. Real-Life Model Testing

For the performance testing, we can use Java Microbenchmark Harness, more information about how to use it can be found in this article.
We have created a separate benchmark for each Converter with specifying BenchmarkMode to Mode.All.
6.1. AverageTime

JMH returned the following results for average running time (less is better) :

6.2. Throughput

In this mode, benchmark returns the number of operations per second. For each of the mappers we’ve received the following results (more is better) :

6.3. SingleShotTime

This mode allows measuring the time of single operation from it’s beginning to the end. The benchmark gave the following results (less is better):

6.4. SampleTime

This mode allows sampling of the time of each operation. Sampling results are split into percentiles, we’ll present results for three different percentiles p0.90, p0.999, and p1.00:

While the exact results of the simple example and the real-life example were clearly different, but they do follow the same trend. Both examples gave similar results in terms of which algorithm is the fastest and which is the slowest one.
6.5. Conclusion

Based on the real-life model testing we performed in this section, we can see that the best performance clearly belongs to MapStruct. In the same tests, we see that Dozer is consistently at the bottom of our results table.

发布了83 篇原创文章 · 获赞 0 · 访问量 849

猜你喜欢

转载自blog.csdn.net/michaelforgood/article/details/103580105