再论ORM性能(续)Moon.ORM4.1修订版发布
此版本中采用了全新的数据获取引擎,采用自动编译加动态代理相结合的方式,性能同时得到有效提高,以下的数据显示:目前除了纯ADO.net,moon的性能几乎是目前所有orm中最高的。关于fish的事情,我再次重申主要目的是反驳其性能高于纯ADO之说,我承认那日测试结果比较浮动,或许可以大家说那日略低于fish.而今日我没有意义再分伯仲.
/*
*测试代码如下
*/
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using ClownFish;
using Dapper;
using Moon.Orm;
namespace TestFish
{
public class OrderInfo
{
public int OrderID { get; set; }
public DateTime OrderDate { get; set; }
public decimal SumMoney { get; set; }
public string Comment { get; set; }
public bool Finished { get; set; }
public int ProductID { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
public string ProductName { get; set; }
public int CategoryID { get; set; }
public string Unit { get; set; }
public string Remark { get; set; }
// 注意:客户信息有可能会是DBNull
public int? CustomerID { get; set; }
public string CustomerName { get; set; }
public string ContactName { get; set; }
public string Address { get; set; }
public string PostalCode { get; set; }
public string Tel { get; set; }
}
class Program
{
static void AppInit()
{
ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["MyNorthwind"];
ConnectionString = setting.ConnectionString;
// 配置 ClownFish
ClownFish.DbContext.RegisterDbConnectionInfo("default", setting.ProviderName, "@", setting.ConnectionString);
Type[] types = ClownFish.BuildManager.FindModelTypesFromCurrentApplication(x => x.Namespace == "TestFish");
ClownFish.BuildManager.CompileModelTypesSync(types, true);
// 配置 FishWebLib
FishWebLib.FishDbContext.Init(setting.ProviderName, "@", setting.ConnectionString);
}
public static SqlConnection GetSqlConnection()
{
var connection = new SqlConnection(ConfigurationManager.AppSettings["linkString"]);
connection.Open();
return connection;
}
protected static string ConnectionString;
private static ClownFish.DbContext db;
public static readonly string QueryText2 = @"
select top (1000) d.OrderID, d.OrderDate, d.SumMoney, d.Comment, d.Finished,
dt.ProductID, dt.UnitPrice, dt.Quantity,
p.ProductName, p.CategoryID, p.Unit, p.Remark,
c.CustomerID, c.CustomerName, c.ContactName, c.Address, c.PostalCode, c.Tel
from Orders d
inner join [Order Details] dt on d.OrderId = dt.OrderId
inner join Products p on dt.ProductId = p.ProductId
left join Customers c on d.CustomerId = c.CustomerId
";
public static void Main(string[] args)
{
//-------------这些可以不理会
var t1=DateTime.Now.Ticks;
AppInit();
db = new ClownFish.DbContext(false);
var parameter = new { TopN =1000 };
var list= ClownFish.DbHelper.FillList<OrderInfo>(
QueryText2, parameter, db, ClownFish.CommandKind.SqlTextWithParams);
var t2=DateTime.Now.Ticks;
Console.WriteLine(t2-t1);
var t3=DateTime.Now.Ticks;
var list2=DBFactory.GetEntities<OrderInfo>(QueryText2);
var t4=DateTime.Now.Ticks;
Console.WriteLine(t4-t3);
//--------------------------------------------------------------------------------------
//--------------------前面的可以不算,咱们正式开始
var tFish1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listFish= ClownFish.DbHelper.FillList<OrderInfo>(
QueryText2, null, db, ClownFish.CommandKind.SqlTextNoParams);
}
var tFish2=DateTime.Now.Ticks;
Console.WriteLine("小鱼的时间:"+(tFish2-tFish1));
var tMoon1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listMoon=DBFactory.GetEntities<OrderInfo>(QueryText2);
}
var tMoon2=DateTime.Now.Ticks;
Console.WriteLine("MOON的时间:"+(tMoon2-tMoon1));
SqlConnection connection = Program.GetSqlConnection();
var tRapper1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listRapper = connection.Query<OrderInfo>(QueryText2, null).ToList<OrderInfo>();
}
var tRapper2=DateTime.Now.Ticks;
Console.WriteLine("datarapper的时间:"+(tRapper2-tRapper1));
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
*测试代码如下
*/
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using ClownFish;
using Dapper;
using Moon.Orm;
namespace TestFish
{
public class OrderInfo
{
public int OrderID { get; set; }
public DateTime OrderDate { get; set; }
public decimal SumMoney { get; set; }
public string Comment { get; set; }
public bool Finished { get; set; }
public int ProductID { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
public string ProductName { get; set; }
public int CategoryID { get; set; }
public string Unit { get; set; }
public string Remark { get; set; }
// 注意:客户信息有可能会是DBNull
public int? CustomerID { get; set; }
public string CustomerName { get; set; }
public string ContactName { get; set; }
public string Address { get; set; }
public string PostalCode { get; set; }
public string Tel { get; set; }
}
class Program
{
static void AppInit()
{
ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["MyNorthwind"];
ConnectionString = setting.ConnectionString;
// 配置 ClownFish
ClownFish.DbContext.RegisterDbConnectionInfo("default", setting.ProviderName, "@", setting.ConnectionString);
Type[] types = ClownFish.BuildManager.FindModelTypesFromCurrentApplication(x => x.Namespace == "TestFish");
ClownFish.BuildManager.CompileModelTypesSync(types, true);
// 配置 FishWebLib
FishWebLib.FishDbContext.Init(setting.ProviderName, "@", setting.ConnectionString);
}
public static SqlConnection GetSqlConnection()
{
var connection = new SqlConnection(ConfigurationManager.AppSettings["linkString"]);
connection.Open();
return connection;
}
protected static string ConnectionString;
private static ClownFish.DbContext db;
public static readonly string QueryText2 = @"
select top (1000) d.OrderID, d.OrderDate, d.SumMoney, d.Comment, d.Finished,
dt.ProductID, dt.UnitPrice, dt.Quantity,
p.ProductName, p.CategoryID, p.Unit, p.Remark,
c.CustomerID, c.CustomerName, c.ContactName, c.Address, c.PostalCode, c.Tel
from Orders d
inner join [Order Details] dt on d.OrderId = dt.OrderId
inner join Products p on dt.ProductId = p.ProductId
left join Customers c on d.CustomerId = c.CustomerId
";
public static void Main(string[] args)
{
//-------------这些可以不理会
var t1=DateTime.Now.Ticks;
AppInit();
db = new ClownFish.DbContext(false);
var parameter = new { TopN =1000 };
var list= ClownFish.DbHelper.FillList<OrderInfo>(
QueryText2, parameter, db, ClownFish.CommandKind.SqlTextWithParams);
var t2=DateTime.Now.Ticks;
Console.WriteLine(t2-t1);
var t3=DateTime.Now.Ticks;
var list2=DBFactory.GetEntities<OrderInfo>(QueryText2);
var t4=DateTime.Now.Ticks;
Console.WriteLine(t4-t3);
//--------------------------------------------------------------------------------------
//--------------------前面的可以不算,咱们正式开始
var tFish1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listFish= ClownFish.DbHelper.FillList<OrderInfo>(
QueryText2, null, db, ClownFish.CommandKind.SqlTextNoParams);
}
var tFish2=DateTime.Now.Ticks;
Console.WriteLine("小鱼的时间:"+(tFish2-tFish1));
var tMoon1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listMoon=DBFactory.GetEntities<OrderInfo>(QueryText2);
}
var tMoon2=DateTime.Now.Ticks;
Console.WriteLine("MOON的时间:"+(tMoon2-tMoon1));
SqlConnection connection = Program.GetSqlConnection();
var tRapper1=DateTime.Now.Ticks;
for (int i = 0; i < 2000; i++) {
var listRapper = connection.Query<OrderInfo>(QueryText2, null).ToList<OrderInfo>();
}
var tRapper2=DateTime.Now.Ticks;
Console.WriteLine("datarapper的时间:"+(tRapper2-tRapper1));
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
欢迎大家公测. /Files/humble/测试项目.zip
moon详情:
QQ群:216965349
少侠,我看你气度不凡天赋异禀,骨骼精奇,这么帅,来了就帮推荐一把吧
我的最近更新