第二篇(性能报告):一个高性能、易用性强、跨数据库的数据库访问框架(性能报告)
下面是所用测试的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HD01SystemModels;
using Model;
using Qin.Data;
using CYQ.Data;
namespace SystemQuestionProc
{
class Program
{
public static List<EventBaseSet> GetEventBaseSetListWhere(string sqlWhere)
{
List<EventBaseSet> list = new List<EventBaseSet>();
var sql = "select * from EventBaseSet";
if (sqlWhere != "") sql += " where " + sqlWhere;
var reader = DBTool.Database.GetDbDataReader(sql);
while (reader.Read())
{
var data = new EventBaseSet();
data.EventID = reader.GetInt64(0);
data.EventName = reader.GetString(1);//注意此字段可能为空
data.Domain = reader.GetString(2);//注意此字段可能为空
data.StartTime = reader.GetDateTime(3);//注意此字段可能为空
data.EndTime = reader.GetDateTime(4);//注意此字段可能为空
//data.LogoPath=reader.GetString(5);//注意此字段可能为空
//data.Descript=reader.GetString(6);//注意此字段可能为空
data.CreateTime = reader.GetDateTime(7);//注意此字段可能为空
//data.Layout=reader.GetString(8);//注意此字段可能为空
data.Style = reader.GetInt32(9);
data.EventType = reader.GetInt32(10);//注意此字段可能为空
data.ShowContactInfo = reader.GetBoolean(11);//注意此字段可能为空
data.ShowMemo = reader.GetString(12);//注意此字段可能为空
data.ShowLock = reader.GetBoolean(13);//注意此字段可能为空
//data.RegistMemo=reader.GetString(14);//注意此字段可能为空
data.RegistLock = reader.GetBoolean(15);//注意此字段可能为空
data.SugestLock = reader.GetBoolean(16);//注意此字段可能为空
//data.BackGroundImg=reader.GetString(17);//注意此字段可能为空
data.EventStage = reader.GetInt32(18);//注意此字段可能为空
data.ShowName = reader.GetBoolean(19);//注意此字段可能为空
data.ShowLogo = reader.GetBoolean(20);//注意此字段可能为空
data.ShowLink = reader.GetBoolean(21);//注意此字段可能为空
//data.AwardTime=reader.GetString(22);//注意此字段可能为空
//data.HeadBGColor=reader.GetString(23);//注意此字段可能为空
//data.HeadBGImage=reader.GetString(24);//注意此字段可能为空
//data.BodyBGColor=reader.GetString(25);//注意此字段可能为空
//data.BodyBGImage=reader.GetString(26);//注意此字段可能为空
data.NowPeriodID = reader.GetInt32(27);
data.UpdateTime = reader.GetDateTime(28);
data.EnabledHeadHtml = reader.GetBoolean(29);
data.EnabledFooterHtml = reader.GetBoolean(30);
//data.HeadHtml=reader.GetString(31);//注意此字段可能为空
// data.FooterHtml=reader.GetString(32);//注意此字段可能为空
data.LimitJoinnerCount = reader.GetInt32(33);
data.Days = reader.GetInt32(34);
//data.WhyClose=reader.GetString(35);//注意此字段可能为空
data.Xuan = reader.GetString(36);
data.AddToPlatformHomePage = reader.GetBoolean(37);
//data.VisitedCount=reader.GetInt64(38);//注意此字段可能为空
//data.AddToUion=reader.GetBoolean(39);//注意此字段可能为空
data.EventModelSelect_SelectID = reader.GetInt32(40);
data.Creater_CreaterID = reader.GetInt32(41);
data.UserRegistSelected_ID = reader.GetInt32(42);
list.Add(data);
}
reader.Close();
return list;
}
public static void Main(string[] args)
{
var t1=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
using(MAction action = new MAction("EventBaseSet"))
{
if (action.Fill("EventID=2"))//查询ID>888的结果中取ID最大的的单行数据
{
var data=action.Data.ToEntity<Model.EventBaseSet>();//UserInfo为实体类。
}
}
}
Console.WriteLine("------CYQ.Data的测试-----");
var t2=DateTime.Now.Ticks;
Console.WriteLine(t2-t1);
Console.WriteLine("-------------------------------");
var t3=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
var sql="select * from EventBaseSet where EventID=2";
var data=DBTool.Database.GetEntity<EventBaseSet>(sql);
}
Console.WriteLine("------Qin.Data的测试-----");
var t4=DateTime.Now.Ticks;
Console.WriteLine(t4-t3);
Console.WriteLine("-------------------------");
var t5=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
var data=GetEventBaseSetListWhere(" EventID=2")[0];
}
Console.WriteLine("------纯sql的测试-----");
var t6=DateTime.Now.Ticks;
Console.WriteLine(t6-t5);
Console.WriteLine("-------------------------");
var t7=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
using (HD01SystemDBEntities db2=new HD01SystemDBEntities()){
var data=db2.EventBaseSet.First(m => m.EventID == 2);
}
}
Console.WriteLine("------实体框架的测试-----");
var t8=DateTime.Now.Ticks;
Console.WriteLine(t8-t7);
Console.WriteLine("-------------------------");
Console.WriteLine("Press any key to continue . . . ");
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HD01SystemModels;
using Model;
using Qin.Data;
using CYQ.Data;
namespace SystemQuestionProc
{
class Program
{
public static List<EventBaseSet> GetEventBaseSetListWhere(string sqlWhere)
{
List<EventBaseSet> list = new List<EventBaseSet>();
var sql = "select * from EventBaseSet";
if (sqlWhere != "") sql += " where " + sqlWhere;
var reader = DBTool.Database.GetDbDataReader(sql);
while (reader.Read())
{
var data = new EventBaseSet();
data.EventID = reader.GetInt64(0);
data.EventName = reader.GetString(1);//注意此字段可能为空
data.Domain = reader.GetString(2);//注意此字段可能为空
data.StartTime = reader.GetDateTime(3);//注意此字段可能为空
data.EndTime = reader.GetDateTime(4);//注意此字段可能为空
//data.LogoPath=reader.GetString(5);//注意此字段可能为空
//data.Descript=reader.GetString(6);//注意此字段可能为空
data.CreateTime = reader.GetDateTime(7);//注意此字段可能为空
//data.Layout=reader.GetString(8);//注意此字段可能为空
data.Style = reader.GetInt32(9);
data.EventType = reader.GetInt32(10);//注意此字段可能为空
data.ShowContactInfo = reader.GetBoolean(11);//注意此字段可能为空
data.ShowMemo = reader.GetString(12);//注意此字段可能为空
data.ShowLock = reader.GetBoolean(13);//注意此字段可能为空
//data.RegistMemo=reader.GetString(14);//注意此字段可能为空
data.RegistLock = reader.GetBoolean(15);//注意此字段可能为空
data.SugestLock = reader.GetBoolean(16);//注意此字段可能为空
//data.BackGroundImg=reader.GetString(17);//注意此字段可能为空
data.EventStage = reader.GetInt32(18);//注意此字段可能为空
data.ShowName = reader.GetBoolean(19);//注意此字段可能为空
data.ShowLogo = reader.GetBoolean(20);//注意此字段可能为空
data.ShowLink = reader.GetBoolean(21);//注意此字段可能为空
//data.AwardTime=reader.GetString(22);//注意此字段可能为空
//data.HeadBGColor=reader.GetString(23);//注意此字段可能为空
//data.HeadBGImage=reader.GetString(24);//注意此字段可能为空
//data.BodyBGColor=reader.GetString(25);//注意此字段可能为空
//data.BodyBGImage=reader.GetString(26);//注意此字段可能为空
data.NowPeriodID = reader.GetInt32(27);
data.UpdateTime = reader.GetDateTime(28);
data.EnabledHeadHtml = reader.GetBoolean(29);
data.EnabledFooterHtml = reader.GetBoolean(30);
//data.HeadHtml=reader.GetString(31);//注意此字段可能为空
// data.FooterHtml=reader.GetString(32);//注意此字段可能为空
data.LimitJoinnerCount = reader.GetInt32(33);
data.Days = reader.GetInt32(34);
//data.WhyClose=reader.GetString(35);//注意此字段可能为空
data.Xuan = reader.GetString(36);
data.AddToPlatformHomePage = reader.GetBoolean(37);
//data.VisitedCount=reader.GetInt64(38);//注意此字段可能为空
//data.AddToUion=reader.GetBoolean(39);//注意此字段可能为空
data.EventModelSelect_SelectID = reader.GetInt32(40);
data.Creater_CreaterID = reader.GetInt32(41);
data.UserRegistSelected_ID = reader.GetInt32(42);
list.Add(data);
}
reader.Close();
return list;
}
public static void Main(string[] args)
{
var t1=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
using(MAction action = new MAction("EventBaseSet"))
{
if (action.Fill("EventID=2"))//查询ID>888的结果中取ID最大的的单行数据
{
var data=action.Data.ToEntity<Model.EventBaseSet>();//UserInfo为实体类。
}
}
}
Console.WriteLine("------CYQ.Data的测试-----");
var t2=DateTime.Now.Ticks;
Console.WriteLine(t2-t1);
Console.WriteLine("-------------------------------");
var t3=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
var sql="select * from EventBaseSet where EventID=2";
var data=DBTool.Database.GetEntity<EventBaseSet>(sql);
}
Console.WriteLine("------Qin.Data的测试-----");
var t4=DateTime.Now.Ticks;
Console.WriteLine(t4-t3);
Console.WriteLine("-------------------------");
var t5=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
var data=GetEventBaseSetListWhere(" EventID=2")[0];
}
Console.WriteLine("------纯sql的测试-----");
var t6=DateTime.Now.Ticks;
Console.WriteLine(t6-t5);
Console.WriteLine("-------------------------");
var t7=DateTime.Now.Ticks;
for (int i = 0; i < 50; i++) {
using (HD01SystemDBEntities db2=new HD01SystemDBEntities()){
var data=db2.EventBaseSet.First(m => m.EventID == 2);
}
}
Console.WriteLine("------实体框架的测试-----");
var t8=DateTime.Now.Ticks;
Console.WriteLine(t8-t7);
Console.WriteLine("-------------------------");
Console.WriteLine("Press any key to continue . . . ");
Console.Read();
}
}
}
总结:
1.实体框架的查询可想而知,这也是我为什么不用它的原因,如果还有异议请告知我如何提高此性能.
2.CYQ.DATA设计方案中的纯反射导致性能降低,建议秋天兄改进之.
3.纯的sql实现,其实我已经写了一个代码生成器,所有的生成代码作为一个不变数据层(不牵扯业务逻辑),也是没有影响的,但我后来发现
当系统中存在着DBNULL时,MSIL的实现方式速度会反而高于纯sql.
如果关注的各路英雄有什么建议和反驳的意见请以实际出发数据说话.请指教
public class EventBaseSet
{
public Int64 EventID
{
get;
set;
}
public static readonly string EventID_ = "EventID";
public String EventName
{
get;
set;
}
public static readonly string EventName_ = "EventName";
public String Domain
{
get;
set;
}
public static readonly string Domain_ = "Domain";
public DateTime StartTime
{
get;
set;
}
public static readonly string StartTime_ = "StartTime";
public DateTime EndTime
{
get;
set;
}
public static readonly string EndTime_ = "EndTime";
public String LogoPath
{
get;
set;
}
public static readonly string LogoPath_ = "LogoPath";
public String Descript
{
get;
set;
}
public static readonly string Descript_ = "Descript";
public DateTime CreateTime
{
get;
set;
}
public static readonly string CreateTime_ = "CreateTime";
public String Layout
{
get;
set;
}
public static readonly string Layout_ = "Layout";
public Int32 Style
{
get;
set;
}
public static readonly string Style_ = "Style";
public Int32 EventType
{
get;
set;
}
public static readonly string EventType_ = "EventType";
public Boolean ShowContactInfo
{
get;
set;
}
public static readonly string ShowContactInfo_ = "ShowContactInfo";
public String ShowMemo
{
get;
set;
}
public static readonly string ShowMemo_ = "ShowMemo";
public Boolean ShowLock
{
get;
set;
}
public static readonly string ShowLock_ = "ShowLock";
public String RegistMemo
{
get;
set;
}
public static readonly string RegistMemo_ = "RegistMemo";
public Boolean RegistLock
{
get;
set;
}
public static readonly string RegistLock_ = "RegistLock";
public Boolean SugestLock
{
get;
set;
}
public static readonly string SugestLock_ = "SugestLock";
public String BackGroundImg
{
get;
set;
}
public static readonly string BackGroundImg_ = "BackGroundImg";
public Int32 EventStage
{
get;
set;
}
public static readonly string EventStage_ = "EventStage";
public Boolean ShowName
{
get;
set;
}
public static readonly string ShowName_ = "ShowName";
public Boolean ShowLogo
{
get;
set;
}
public static readonly string ShowLogo_ = "ShowLogo";
public Boolean ShowLink
{
get;
set;
}
public static readonly string ShowLink_ = "ShowLink";
public String AwardTime
{
get;
set;
}
public static readonly string AwardTime_ = "AwardTime";
public String HeadBGColor
{
get;
set;
}
public static readonly string HeadBGColor_ = "HeadBGColor";
public String HeadBGImage
{
get;
set;
}
public static readonly string HeadBGImage_ = "HeadBGImage";
public String BodyBGColor
{
get;
set;
}
public static readonly string BodyBGColor_ = "BodyBGColor";
public String BodyBGImage
{
get;
set;
}
public static readonly string BodyBGImage_ = "BodyBGImage";
public Int32 NowPeriodID
{
get;
set;
}
public static readonly string NowPeriodID_ = "NowPeriodID";
public DateTime UpdateTime
{
get;
set;
}
public static readonly string UpdateTime_ = "UpdateTime";
public Boolean EnabledHeadHtml
{
get;
set;
}
public static readonly string EnabledHeadHtml_ = "EnabledHeadHtml";
public Boolean EnabledFooterHtml
{
get;
set;
}
public static readonly string EnabledFooterHtml_ = "EnabledFooterHtml";
public String HeadHtml
{
get;
set;
}
public static readonly string HeadHtml_ = "HeadHtml";
public String FooterHtml
{
get;
set;
}
public static readonly string FooterHtml_ = "FooterHtml";
public Int32 LimitJoinnerCount
{
get;
set;
}
public static readonly string LimitJoinnerCount_ = "LimitJoinnerCount";
public Int32 Days
{
get;
set;
}
public static readonly string Days_ = "Days";
public String WhyClose
{
get;
set;
}
public static readonly string WhyClose_ = "WhyClose";
public String Xuan
{
get;
set;
}
public static readonly string Xuan_ = "Xuan";
public Boolean AddToPlatformHomePage
{
get;
set;
}
public static readonly string AddToPlatformHomePage_ = "AddToPlatformHomePage";
public Int64 VisitedCount
{
get;
set;
}
public static readonly string VisitedCount_ = "VisitedCount";
public Boolean AddToUion
{
get;
set;
}
public static readonly string AddToUion_ = "AddToUion";
public Int32 EventModelSelect_SelectID
{
get;
set;
}
public static readonly string EventModelSelect_SelectID_ = "EventModelSelect_SelectID";
public Int32 Creater_CreaterID
{
get;
set;
}
public static readonly string Creater_CreaterID_ = "Creater_CreaterID";
public Int32 UserRegistSelected_ID
{
get;
set;
}
public static readonly string UserRegistSelected_ID_ = "UserRegistSelected_ID";
}
{
public Int64 EventID
{
get;
set;
}
public static readonly string EventID_ = "EventID";
public String EventName
{
get;
set;
}
public static readonly string EventName_ = "EventName";
public String Domain
{
get;
set;
}
public static readonly string Domain_ = "Domain";
public DateTime StartTime
{
get;
set;
}
public static readonly string StartTime_ = "StartTime";
public DateTime EndTime
{
get;
set;
}
public static readonly string EndTime_ = "EndTime";
public String LogoPath
{
get;
set;
}
public static readonly string LogoPath_ = "LogoPath";
public String Descript
{
get;
set;
}
public static readonly string Descript_ = "Descript";
public DateTime CreateTime
{
get;
set;
}
public static readonly string CreateTime_ = "CreateTime";
public String Layout
{
get;
set;
}
public static readonly string Layout_ = "Layout";
public Int32 Style
{
get;
set;
}
public static readonly string Style_ = "Style";
public Int32 EventType
{
get;
set;
}
public static readonly string EventType_ = "EventType";
public Boolean ShowContactInfo
{
get;
set;
}
public static readonly string ShowContactInfo_ = "ShowContactInfo";
public String ShowMemo
{
get;
set;
}
public static readonly string ShowMemo_ = "ShowMemo";
public Boolean ShowLock
{
get;
set;
}
public static readonly string ShowLock_ = "ShowLock";
public String RegistMemo
{
get;
set;
}
public static readonly string RegistMemo_ = "RegistMemo";
public Boolean RegistLock
{
get;
set;
}
public static readonly string RegistLock_ = "RegistLock";
public Boolean SugestLock
{
get;
set;
}
public static readonly string SugestLock_ = "SugestLock";
public String BackGroundImg
{
get;
set;
}
public static readonly string BackGroundImg_ = "BackGroundImg";
public Int32 EventStage
{
get;
set;
}
public static readonly string EventStage_ = "EventStage";
public Boolean ShowName
{
get;
set;
}
public static readonly string ShowName_ = "ShowName";
public Boolean ShowLogo
{
get;
set;
}
public static readonly string ShowLogo_ = "ShowLogo";
public Boolean ShowLink
{
get;
set;
}
public static readonly string ShowLink_ = "ShowLink";
public String AwardTime
{
get;
set;
}
public static readonly string AwardTime_ = "AwardTime";
public String HeadBGColor
{
get;
set;
}
public static readonly string HeadBGColor_ = "HeadBGColor";
public String HeadBGImage
{
get;
set;
}
public static readonly string HeadBGImage_ = "HeadBGImage";
public String BodyBGColor
{
get;
set;
}
public static readonly string BodyBGColor_ = "BodyBGColor";
public String BodyBGImage
{
get;
set;
}
public static readonly string BodyBGImage_ = "BodyBGImage";
public Int32 NowPeriodID
{
get;
set;
}
public static readonly string NowPeriodID_ = "NowPeriodID";
public DateTime UpdateTime
{
get;
set;
}
public static readonly string UpdateTime_ = "UpdateTime";
public Boolean EnabledHeadHtml
{
get;
set;
}
public static readonly string EnabledHeadHtml_ = "EnabledHeadHtml";
public Boolean EnabledFooterHtml
{
get;
set;
}
public static readonly string EnabledFooterHtml_ = "EnabledFooterHtml";
public String HeadHtml
{
get;
set;
}
public static readonly string HeadHtml_ = "HeadHtml";
public String FooterHtml
{
get;
set;
}
public static readonly string FooterHtml_ = "FooterHtml";
public Int32 LimitJoinnerCount
{
get;
set;
}
public static readonly string LimitJoinnerCount_ = "LimitJoinnerCount";
public Int32 Days
{
get;
set;
}
public static readonly string Days_ = "Days";
public String WhyClose
{
get;
set;
}
public static readonly string WhyClose_ = "WhyClose";
public String Xuan
{
get;
set;
}
public static readonly string Xuan_ = "Xuan";
public Boolean AddToPlatformHomePage
{
get;
set;
}
public static readonly string AddToPlatformHomePage_ = "AddToPlatformHomePage";
public Int64 VisitedCount
{
get;
set;
}
public static readonly string VisitedCount_ = "VisitedCount";
public Boolean AddToUion
{
get;
set;
}
public static readonly string AddToUion_ = "AddToUion";
public Int32 EventModelSelect_SelectID
{
get;
set;
}
public static readonly string EventModelSelect_SelectID_ = "EventModelSelect_SelectID";
public Int32 Creater_CreaterID
{
get;
set;
}
public static readonly string Creater_CreaterID_ = "Creater_CreaterID";
public Int32 UserRegistSelected_ID
{
get;
set;
}
public static readonly string UserRegistSelected_ID_ = "UserRegistSelected_ID";
}
少侠,我看你气度不凡天赋异禀,骨骼精奇,这么帅,来了就帮推荐一把吧
我的最近更新