zoukankan      html  css  js  c++  java
  • [.NetCore] 下Mapper 测试 传统映射 vs EmitMapper vs AutoMapper

    Nuget 下版本

    测试代码

    using System;
    using AutoMapper;
    using System.Diagnostics;
    using EmitMapper;
    
    namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
                var student = new Student
                {
                    Name= "test",
                    No = "1234567896766666666666666666666666666666666666666666",
                };
                var watch = new Stopwatch();
                int count = 10000000;
    
     
                Console.WriteLine();
                Console.WriteLine("Automapper 映射测试");
                MapperConfiguration configuration = new MapperConfiguration(
                    cfg =>
                    {
                        cfg.CreateMap<Student, StudentDto>();
                    });
                var mapper = configuration.CreateMapper();
                watch.Start();
                for (int i = 0; i < count; ++i)
                {
                    var studentdto = mapper.Map<Student, StudentDto>(student);
                }
                watch.Stop();
                Console.WriteLine($"时间消耗:{watch.ElapsedMilliseconds}ms");
    
                Console.WriteLine();
                Console.WriteLine("EmitMapper 映射测试");
                ObjectsMapper<Student, StudentDto> emitMap = ObjectMapperManager.DefaultInstance.GetMapper<Student, StudentDto>();
                watch.Restart();
                for (int i = 0; i < count; ++i)
                {
                    StudentDto studentdt = emitMap.Map(student);
                }
                watch.Stop();
                Console.WriteLine($"时间消耗:{watch.ElapsedMilliseconds}ms");
    
                Console.WriteLine("
    传统方法普通映射");
                watch.Restart();
                for (int i = 0; i < count; ++i)
                {
                    var studentDto = new StudentDto
                    {
                        Name = student.Name,
                        No = student.No,
                    };
                }
                watch.Stop();
                Console.WriteLine($"时间消耗:{watch.ElapsedMilliseconds}ms");
    
    
    
    
    
            }
        }
    
        public class StudentDto
        {
            public string Name{ get; set; }
            public string No { get; set; }
        }
    
        public class Student
        {
            public string Name{ get; set; }
            public string No { get; set; }
        }
    }
    
    

    测试结果

    速度对比:
    AutoMapper ~ 10倍 传统映射
    EmitMapper ~ 1.5倍 传统映射

    PS:不考虑系统栈等等其他开销的情况下

  • 相关阅读:
    ORACLE PL/SQL使用经验总结 [转]
    网页表单项Input的高级限制级用法 [转]
    Zend_Search_Lucene索引更新
    Zend Framework 1.10.1 开始使用 Zend_Search_Lucene
    使用zend Framework的lucene进行全文检索——中文分词
    SQL to Select a random row from a database table
    php源代码之函数集介绍
    Zend Framework之Search_Lucene实例
    array_multisort根据字段给数组排序
    php soap实例讲解
  • 原文地址:https://www.cnblogs.com/minskiter/p/11573800.html
Copyright © 2011-2022 走看看