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,性能不至于差如此之远!

完整测试代码下载

posted @ 2011-04-08 17:19  Repository  阅读(6416)  评论(8编辑  收藏  举报