1 Star 0 Fork 646

camark/Masuit.Tools

forked from 懒得勤快/Masuit.Tools 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Program.cs 7.71 KB
一键复制 编辑 原始数据 按行查看 历史
懒得勤快 提交于 2019-08-30 22:10 . 升级包
using AutoMapper;
using Masuit.Tools.Mapping;
using Masuit.Tools.Systems;
using System;
using System.Collections.Generic;
namespace Masuit.Tools.ExpressionMapperBenchmark
{
class Program
{
static void Main(string[] args)
{
#region 配置automapper
var mapper = new MapperConfiguration(e =>
{
e.CreateMap<TestClassA, TestClassB>().ReverseMap();
e.CreateMap<TestClassC, TestClassD>().ReverseMap();
}).CreateMapper();
#endregion
#region 配置ExpressionMapper
ExpressionMapper.CreateMap<TestClassA, TestClassB>().ReverseMap();
ExpressionMapper.CreateMap<TestClassC, TestClassD>().ReverseMap();
#endregion
#region 造一个大对象
var a = new TestClassA()
{
MyProperty = "ssssssssssssssssssssss",
DateTime = DateTime.Now,
Double = 123.33,
Int = 100,
TestClassC = new TestClassC()
{
MyProperty = "ccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddd",
Obj = new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 23458894.555,
Int = 10100000,
Obj = new TestClassD()
}
}
},
List = new List<TestClassC>()
{
new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddddddddddddd",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassC()
{
MyProperty = "cccccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
}
}
},
new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddddddddddddd",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassC()
{
MyProperty = "cccccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
}
}
},
new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddddddddddddd",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassC()
{
MyProperty = "cccccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
}
}
},
new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddddddddddddd",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassC()
{
MyProperty = "cccccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
}
}
},
new TestClassC()
{
MyProperty = "cccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
{
MyProperty = "ddddddddddddddddddddddddddddddddddd",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassC()
{
MyProperty = "cccccccccccccccccccccccccccccc",
DateTime = DateTime.Now,
Double = 2345.555,
Int = 10100,
Obj = new TestClassD()
}
}
},
}
};
#endregion
var time = HiPerfTimer.Execute(() =>
{
a.Map<TestClassA, TestClassB>();
a.Map<TestClassA, TestClassB>();
});
Console.WriteLine($"ExpressionMapper映射2次耗时:{time}s");
time = HiPerfTimer.Execute(() =>
{
for (int i = 0; i < 1000000; i++)
{
var b = a.Map<TestClassA, TestClassB>();
}
});
Console.WriteLine($"ExpressionMapper映射100000次耗时:{time}s");
time = HiPerfTimer.Execute(() =>
{
mapper.Map<TestClassB>(a);
mapper.Map<TestClassB>(a);
});
Console.WriteLine($"AutoMapper映射2次耗时:{time}s");
time = HiPerfTimer.Execute(() =>
{
for (int i = 0; i < 1000000; i++)
{
var b = mapper.Map<TestClassB>(a);
}
});
Console.WriteLine($"AutoMapper映射100000次耗时:{time}s");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/camark/Masuit.Tools.git
git@gitee.com:camark/Masuit.Tools.git
camark
Masuit.Tools
Masuit.Tools
master

搜索帮助