发射映射器vs值注入器或自动映射器性能 [英] Emit mapper vs valueinjecter or automapper performance

查看:150
本文介绍了发射映射器vs值注入器或自动映射器性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间来比较这三个映射器,有趣的是,为什么emitmapper与任何valueinjecter或automapper之间的性能差异如此之大(最后两个按性能可比)。从emitmapper解决方案中的基准测试(1000000次迭代):

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). From benchmark test in emitmapper solution (1000000 iterations):

    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

还有一些来自valueinjecter的基准测试,运行了添加的emitmapper(用于10000次迭代):

Also some benchmarks from valueinjecter runned with added emitmapper(for 10000 iterations):

    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.

考虑到这一点,导致valueinjecter(也称为automapper)的结果比发出mapper的结果慢100倍。如此巨大的性能差异是什么原因?对于我来说,对象到对象的映射器与手写映射器相比并不需要花费太多时间,因为它是项目的瓶颈(例如,如果我们需要映射对象的集合)。

Taking this into account, have result as valueinjecter(also as automapper) slower than in 100 times than emit mapper. 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).

推荐答案

原因已在 EmitMapper文档


它有效地使用了Emit库,可以在运行时直接在IL中生成映射器,就像这些映射器是手工编写的一样。大多数其他映射器使用反射库进行映射(或生成源代码)。此外,EmitMapper在映射期间最大程度地减少了装箱/拆箱操作和其他调用。例如,它可以对值类型执行类型转换而无需装箱-拆箱,并在可能的情况下转换嵌套成员而无需递归(一次通过算法)。

It effectively uses the Emit library to generate mappers at run-time direct in IL as though these mappers are written by hand. Most other mappers use the Reflection library for mapping (or source code generation). Also EmitMapper minimizes boxing-unboxing operations and additional calls during mapping. 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.

与手写代码相比,反射非常慢。与手写映射相比,EmitMapper发出时仅具有启动开销。

Reflection is extremely slow compared to handwritten code. EmitMapper instead, compared to handwritten mapping, has only the startup overhead when it emits.

这篇关于发射映射器vs值注入器或自动映射器性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆