这是更快:Automapper,Valuinjector,或手动映射?到什么程度,是每一个速度更快? [英] Which is faster: Automapper, Valuinjector, or manual mapping? To what degree is each one faster?

查看:224
本文介绍了这是更快:Automapper,Valuinjector,或手动映射?到什么程度,是每一个速度更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我有这个对象在我的DAL(ORM等)

 公共类学生
{
   公共字符串名称{获取;集;}
   公共字符串的地址{获取;集;}
   公共字符串电话{获取;集;}
   公共父父{获取;集;}
}
公共类父
{
   公共字符串名称{获取;集;}
   公共字符串的地址{获取;集;}
   公共字符串电话{获取;集;}
}
 

和我有一个视图模型,看起来像这样

 公共类StudentDetailVM
{
   公共字符串名称{获取;集;}
   公共字符串的地址{获取;集;}
   公共字符串电话{获取;集;}

   公共字符串ParentName {获取;集;}
   公共字符串ParentPhone {获取;集;}
}
 

在这种情况下,我需要拼合的对象。我能做到这一点与像Automapper,ValueInjector的工具,我也可以做手工。这是单调乏味的工作,如果有很多这样的类来处理,但似乎有三种方法之间的性能/开发效率的权衡。

我在寻找指导时使用 Automapper VS的 Valueinjector 的VS手工映射。我敢肯定,手动映射是最快的国家之一,但多少呢?

  
      
  1. 是某些情况下慢得多/比别人快(如扁平化,等等)?

  2.   
  3. 难道意义做一个混合的方法,以层之间的映射对象呢?

  4.   

我想问的原因是因为codePLEX的项目称为emitmapper的成立是为了解决性能问题automapper,我记得看到一个评论说,说automapper可能需要.5ms映射一个大类。 (参考需要)

我还记得看到,描述用户如何可以选择留在您的网站如果这是在70ms的加载,而不是90毫秒以上的机会较高的文章。 (我在寻找这种联系太)。如果automapper消耗了我大部分的页面加载速度,再加上网络延迟,那么,我认为潜力不使用automapper和我的高容量的网页创建手工类和坚持一个混合的方法。

底线:我会运行测试自己,但我不知道有足够的了解.NET内部创建一个可作为可重复使用的指导原则准确的结果。

解决方案
  

底线:我会运行测试自己,但我不知道有足够的了解.NET内部创建一个可作为可重复使用的指导原则准确的结果。

您并不需要了解.NET内部。你只需要知道你的性能要求和你的典型用法是将会是什么样的。简介在一个典型的使用场景中,code,在所有各种不同的方式,并选择满足您的性能需求,是最简单的维护(即不一定选择最高效的;有其他标准)。

Suppose I have this object in my DAL (ORM etc)

public class Student
{
   public string Name {get;set;}
   public string Address {get;set;}
   public string Phone {get;set;}
   public Parent Parent {get;set;}
}
public class Parent
{
   public string Name {get;set;}
   public string Address {get;set;}
   public string Phone {get;set;}
}

And I have a ViewModel that looks like this

public class StudentDetailVM
{
   public string Name {get;set;}
   public string Address {get;set;}
   public string Phone {get;set;}

   public string ParentName {get;set;}
   public string ParentPhone {get;set;}
}

In that case I need to flatten the objects. I can do this with a tool like Automapper, ValueInjector, or I could do it manually. This is tedious work if there are many such classes to handle, but there appears to be a performance / developer efficiency tradeoff between all three approaches.

I'm looking for guidance on when to use Automapper vs Valueinjector vs a manual mapping. I'm sure manual mapping is the fastest one, but by how much?

  1. Are some scenarios much slower/faster than others (e.g. flattening, etc)?

  2. Would it make sense to do a hybrid approach to mapping objects between layers?

The reason I ask is because a Codeplex project called emitmapper was created to address performance issues in automapper, and I remember seeing a comment that said automapper may take up to .5ms to map a large class. (reference needed)

I also remember seeing an article that describes how users have a higher chance of staying on your site if it loads within 70ms, as opposed to 90ms or more. (I'm looking for this link too). If automapper is consuming most of my page-load time, combined with network latency, then I see potential to not use automapper and create manual classes for my high volume pages and stick with a hybrid approach.

Bottom line: I would run the tests myself, but I don't know enough about .NET internals to create accurate results that can be used as a reusable guideline.

解决方案

Bottom line: I would run the tests myself, but I don't know enough about .NET internals to create accurate results that can be used as a reusable guideline.

You don't need to know .NET internals. You just need to know what your performance requirements are and what your typical usage is going to look like. Profile the code under a typical usage scenario in the all the variety of ways, and choose that which meets your performance requirements and is easiest to maintain (i.e., don't necessarily choose the most performant; there are other criteria).

这篇关于这是更快:Automapper,Valuinjector,或手动映射?到什么程度,是每一个速度更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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