zoukankan      html  css  js  c++  java
  • NLiteMapper与EmitMapper性能简单比较

    风云(老看成 云风)要求,简单测试了下NLiteMapper的性能,顺道与Emit方式作一下性能比较,不知道是我应用不得当还是有什么其它原因,不知道为什么NLite性性能较之EmitMapper如如此大的差别,看看我的测试代码:

    static void Main(string[] args)
    {
        //consturct data
        List<SimpleClassFrom> fromCollection = new List<SimpleClassFrom>();
        int count = 10000;
        for (int i = 0; i < count; i++)
        {
            SimpleClassFrom from = new SimpleClassFrom
            {
                ID = 123456,
                Name = "test",
                Age = 30,
                Email = "hhhhhhhhhhhhhhh@hotmail.com"
            };
            fromCollection.Add(from);
        }
     
     
        //test nlite mapper
        NLite.Mapping.IMapper<SimpleClassFrom, SimpleClassTo> a = NLite.Mapper.CreateMapper<SimpleClassFrom, SimpleClassTo>();
     
        Stopwatch sw = Stopwatch.StartNew();
        sw.Start();
        for (int i = 0; i < count; i++)
        {
            a.Map(fromCollection[i]);
        }
     
        sw.Stop();
     
        Console.WriteLine("nlitemapper elapsed:{0}ms", sw.ElapsedMilliseconds);
     
     
        //test emit mapper
        EmitMapper.ObjectsMapper<SimpleClassFrom,SimpleClassTo> mapper = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<SimpleClassFrom, SimpleClassTo>();
     
     
        
        sw.Restart();
        for (int i = 0; i < count; i++)
        {
            mapper.Map(fromCollection[i]);
        }
        sw.Stop();
     
        Console.WriteLine("emitmapper elapsed:{0}ms", sw.ElapsedMilliseconds);
     
        Console.Read();
    }

      我只mapper了10000个对象,看看测试结果

    测试结果:

    result

    NLite Mapper具体实现我没看,有空看看,风云说是用Emit方式实现Mapper,性能不至于差如此之远!

    完整测试代码下载

  • 相关阅读:
    5.7填数字游戏求解
    5.6判断回文数字
    5.5百钱买百鸡问题
    5.4三色球问题
    5.3哥德巴赫猜想的近似证明
    5.2求两个数的最大公约数和最小公倍数
    5.1舍罕王的失算
    4.19递归反向输出字符串
    Elasticsearch 安装
    linux 安装nginx步骤
  • 原文地址:https://www.cnblogs.com/repository/p/2009713.html
Copyright © 2011-2022 走看看