博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自己的TableDataEntity、手工代码绑定实体、反射绑定实体性能对比
阅读量:6457 次
发布时间:2019-06-23

本文共 5456 字,大约阅读时间需要 18 分钟。

   最近一直在研究怎么超越手工代码绑定实体性能,但是还是没有实现,贴出研究过程中的产物:

 

public class PerformanceTest    {        int count = 100000;        public string GetTestInfo()        {            StringBuilder content = new StringBuilder();            System.Diagnostics.Stopwatch oTime = new System.Diagnostics.Stopwatch();            oTime.Start();             GetDataFor();            oTime.Stop();            content.Append(" 实体赋值用时:").Append(oTime.Elapsed.Seconds).Append("秒  ").AppendLine(oTime.Elapsed.Ticks.ToString());            oTime = new System.Diagnostics.Stopwatch();            oTime.Start();            GetfsDataFor();            oTime.Stop();            content.Append(" 反射实体赋值用时:").Append(oTime.Elapsed.Seconds).Append("秒  ").AppendLine(oTime.Elapsed.Ticks.ToString());            oTime = new System.Diagnostics.Stopwatch();            oTime.Start();            GetMyTableDataFor();            oTime.Stop();            content.Append(" 我的二维表格对象实体赋值用时:").Append(oTime.Elapsed.Seconds).Append("秒  ").AppendLine(oTime.Elapsed.Ticks.ToString());                                    //OrderInfo uu  = GetEntiy
(); return content.ToString(); } #region 我的二维表格实体 private Globe.Database.TableDataEntity GetMyTableDataFor() { Globe.Database.TableDataEntity tableData = new Globe.Database.TableDataEntity(); for (int i = 0; i < count; i++) { tableData.Add(LoadMyRow()); } return tableData; } private Globe.Database.RowDataEntity LoadMyRow() { Globe.Database.RowDataEntity row = new Globe.Database.RowDataEntity(); row.Fileds.Add("Address", "这是一个地址,武汉市新洲区双柳街"); row.Fileds.Add("CategoryID", "999999"); row.Fileds.Add("Comment", "信息信息信息信息信息信息信息信息信息信息信息信息信息信息信息信息"); row.Fileds.Add("ContactName", "名字名字名字"); row.Fileds.Add("CustomerID", "1"); row.Fileds.Add("CustomerName", "名字名字名字"); row.Fileds.Add("Finished", "FinishedFinished"); row.Fileds.Add("OrderDate","2012-03-03 22:22:22 222"); row.Fileds.Add("OrderID","55555555"); row.Fileds.Add("PostalCode","2.2.2.2.2.2"); row.Fileds.Add("ProductID","343434"); row.Fileds.Add("ProductName","ProductNameProductNameProductNameProductName"); row.Fileds.Add("Quantity","QuantityQuantityQuantityQuantityQuantity"); row.Fileds.Add("Remark","RemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemark"); row.Fileds.Add("SumMoney","SumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoney"); row.Fileds.Add("Tel","13343583268"); row.Fileds.Add("Unit","ttttttttttttttt"); row.Fileds.Add("UnitPrice","http://www.cnblogs.com/shunhe316/archive/2012/08/30/2664667.html"); return row; } #endregion #region 手工实体 private List
GetDataFor() { List
info = new List
(); for (int i = 0; i < count; i++) { info.Add(LoadOrderInfo()); } return info; } private OrderInfo LoadOrderInfo() { OrderInfo info = new OrderInfo(); info.Address = "这是一个地址,武汉市新洲区双柳街"; info.CategoryID = "999999"; info.Comment = "信息信息信息信息信息信息信息信息信息信息信息信息信息信息信息信息"; info.ContactName = "名字名字名字"; info.CustomerID = "1"; info.CustomerName = "名字名字名字"; info.Finished = "FinishedFinished"; info.OrderDate = "2012-03-03 22:22:22 222"; info.OrderID = "55555555"; info.PostalCode = "2.2.2.2.2.2"; info.ProductID = "343434"; info.ProductName = "ProductNameProductNameProductNameProductName"; info.Quantity = "QuantityQuantityQuantityQuantityQuantity"; info.Remark = "RemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemarkRemark"; info.SumMoney = "SumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoneySumMoney"; info.Tel = "13343583268"; info.Unit = "ttttttttttttttt"; info.UnitPrice = "http://www.cnblogs.com/shunhe316/archive/2012/08/30/2664667.html"; return info; } #endregion #region 反射实体 private List
GetfsDataFor() { List
info = new List
(); for (int i = 0; i < count; i++) { info.Add(GetEntiy < OrderInfo>()); } return info; } public T GetEntiy
() where T : new() { T info = new T(); System.Reflection.PropertyInfo propertyInfo = typeof(T).GetProperty(""); //得到实体类属性的集合 PropertyInfo[] properties = typeof(T).GetProperties(); foreach (PropertyInfo fieldInfo in properties)//遍历数组 { fieldInfo.SetValue(info, "我的二维表格我的二维表格我的二维表格", null); } return info; } #endregion }

 

循环绑定100000次,最终运行结果:

 实体手工绑定赋值用时:0秒        时间刻度:656027

 反射实体绑定赋值用时:3秒        时间刻度:36066423
 我的二位表格对象实体赋值用时:1秒    时间刻度:13217015

 

转载于:https://www.cnblogs.com/shunhe316/archive/2013/01/19/2867215.html

你可能感兴趣的文章
js中的json语法
查看>>
使用百度地图实现基本的地图显示与定位功能
查看>>
都说Python是最佳编程入门语言,为什么你学习却是如此坎坷?
查看>>
利用windows.h头文件写一个简单的C语言倒计时
查看>>
过滤器
查看>>
MyBatsi-Mapper映射文件
查看>>
Entity Framework技术系列之2:三种开发模式实现数据访问
查看>>
SpringMVC 处理器执行链 (HandlerMapping)的执行过程
查看>>
Oracle EBS-SQL (PO-14):检查报价单与成本对比.sql
查看>>
react组件间传值详解
查看>>
Exceptions: Database Exceptions (MSDN)
查看>>
prettytable模块(格式化打印内容)
查看>>
淘宝一月上钻是这样操作的
查看>>
Debugging Failed Because Integrated windows authentication is not enabled
查看>>
hdu-1541-Stars (树状数组)
查看>>
ASP.NET中的Request、Response、Server对象
查看>>
【Foreign】不等式 [数论]
查看>>
【Foreign】Game [博弈论][DP]
查看>>
【AtCoder Grand Contest 007E】Shik and Travel [Dfs][二分答案]
查看>>
python中文问题汇总
查看>>