简体   繁体   English

发射映射器与valueinjecter或automapper性能

[英]Emit mapper vs valueinjecter or automapper performance

I have spent some time comparing this three mappers and it is interesting why so big performance diffrenece between emitmapper and any of valueinjecter or automapper(last two comparable by performance). 我花了一些时间比较这三个映射器,有趣的是为什么在emitmapper和任何valueinjecter或者automapper之间有如此大的性能差异(最后两个可以通过性能进行比较)。 From benchmark test in emitmapper solution (1000000 iterations): 来自emitmapper解决方案的基准测试(1000000次迭代):

    Auto Mapper (simple):        38483 milliseconds
    Emit Mapper (simple):        118 milliseconds
    Handwritten Mapper (simple): 37 milliseconds

    Auto Mapper (Nested):        53800 milliseconds
    Emit Mapper (Nested):        130 milliseconds
    Handwritten Mapper (Nested): 128 milliseconds

    Auto Mapper (Custom):        49587 milliseconds
    Emit Mapper (Custom):        231 milliseconds

Also some benchmarks from valueinjecter runned with added emitmapper(for 10000 iterations): 还有一些来自valueinjecter的基准测试运行了添加的emitmapper(10000次迭代):

    Convention: 00:00:00.5016074
    Automapper: 00:00:00.1992945 
    Smart convention: 00:00:00.2132185
    Emit mapper(each time new mapper): 00:00:00.1168676
    Emit mapper(one mapper): 00:00:00.0012337

There in first emit mapper test - it was created each time, in second - one mapper for all conversions. 首先发射映射器测试 - 每次创建它,第二次 - 所有转换的一个映射器。

Taking this into account, have result as valueinjecter(also as automapper) slower than in 100 times than emit mapper. 考虑到这一点,作为valueinjecter(也作为automapper)的结果比发射映射器的结果慢100倍。 What is a reason of so huge performance difference? 这么大的性能差异是什么原因造成的? As for me object to object mapper cannot took so much time comparing to handwritten mapper as it be a bottleneck of project(if we need to map collection of objects for example). 至于我对象,对象映射器与手写映射器相比不能花费那么多时间,因为它是项目的瓶颈(例如,如果我们需要映射对象的集合)。

At this moment I'm thinking about using emit mapper, but only one reason why I'm not ready to decide: emit mapper not supported at all by first developers, but I'm not sure that this is very important(very low possibility to requirement of some additional functionality). 此刻我正在考虑使用emit mapper,但只有一个原因我还没准备好决定:首先开发人员根本不支持发射映射器,但我不确定这是非常重要的(非常低的可能性)要求一些额外的功能)。

The reason is explained int the EmitMapper documentation : 原因在EmitMapper文档中解释:

It effectively uses the Emit library to generate mappers at run-time direct in IL as though these mappers are written by hand. 它有效地使用Emit库在IL中直接在运行时生成映射器,就好像这些映射器是手动编写的一样。 Most other mappers use the Reflection library for mapping (or source code generation). 大多数其他映射器使用Reflection库进行映射(或源代码生成)。 Also EmitMapper minimizes boxing-unboxing operations and additional calls during mapping. 此外,EmitMapper在映射期间最小化装箱拆箱操作和其他调用。 For example it performs type conversion for value-types without boxing-unboxing and converts nested members without recursion (one-pass algorithm) when it is possible. 例如,它在没有装箱拆箱的情况下对值类型执行类型转换,并在可能的情况下转换嵌套成员而不进行递归(一次通过算法)。

Reflection is extremely slow compared to handwritten code. 与手写代码相比,反射速度极慢。 EmitMapper instead, compared to handwritten mapping, has only the startup overhead when it emits. 相比,EmitMapper与手写映射相比,在发出时只有启动开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM