驳Fish的ORM性能问题.如有疑问大家公测.


一下是测试代码.代码采用fish给的.数据库也是他给的./Files/humble/TestFish.7z

 //

/*
 * 由SharpDevelop创建。
 * 用户: Administrator
 * 日期: 2012/8/20
 * 时间: 10:50
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 
*/
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 { getset; }
        public DateTime OrderDate { getset; }
        public decimal SumMoney { getset; }
        public string Comment { getset; }
        public bool Finished { getset; }
        public int ProductID { getset; }
        public decimal UnitPrice { getset; }
        public int Quantity { getset; }
        public string ProductName { getset; }
        public int CategoryID { getset; }
        public string Unit { getset; }
        public string Remark { getset; }
        
        // 注意:客户信息有可能会是DBNull
        public int? CustomerID { getset; }
        public string CustomerName { getset; }
        public string ContactName { getset; }
        public string Address { getset; }
        public string PostalCode { getset; }
        public string Tel { getset; }
    }
    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 == "PerformanceTestApp.Model");
            ClownFish.BuildManager.CompileModelTypesSync(types, true);

            // 配置 FishWebLib
            FishWebLib.FishDbContext.Init(setting.ProviderName, "@", setting.ConnectionString);
        }
        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 SqlConnection GetSqlConnection()
        {
            var connection = new SqlConnection(ConfigurationManager.AppSettings["linkString"]);
            connection.Open();
            return connection;
        }
        
        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, null, 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);
            SqlConnection connection = Program.GetSqlConnection();
            //--------------------------------------------------------------------------------------
            
            
            var dd = connection.Query<OrderInfo>(QueryText2, null).ToList<OrderInfo>();
            
            //--------------------前面的可以不算,咱们正式开始
            var tFish1=DateTime.Now.Ticks;
            for (int i = 0; i < 1000; i++) {
                var listFish= ClownFish.DbHelper.FillList<OrderInfo>(
                    QueryText2, null, db, ClownFish.CommandKind.SqlTextWithParams);
            }
            var tFish2=DateTime.Now.Ticks;
            Console.WriteLine("小鱼的时间:"+(tFish2-tFish1));
            //------------------
            var tMoon1=DateTime.Now.Ticks;
            for (int i = 0; i < 1000; i++) {
                var listMoon=DBFactory.GetEntities<OrderInfo>(QueryText2);
            }
            var tMoon2=DateTime.Now.Ticks;
            Console.WriteLine("MOON的时间:"+(tMoon2-tMoon1));
            
            var tRapper1=DateTime.Now.Ticks;
            for (int i = 0; i < 1000; 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);
        }
    }
}

 测试结果图:

 

//

 

posted @ 2012-08-20 11:33  [秦时明月]  阅读(6403)  评论(83编辑  收藏  举报