mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 22:25:49 +08:00
Update Demo
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Data.SqlClient;
|
||||
using Dapper;
|
||||
using SqlSugar;
|
||||
using Dapper.Contrib.Extensions;
|
||||
using System.Data.Entity;
|
||||
|
||||
namespace PerformanceTest.TestItems
|
||||
{
|
||||
@@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
||||
{
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试一次读取100万条数据的速度");
|
||||
var eachCount = 1;
|
||||
|
||||
@@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -63,5 +68,19 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.TestList.AsNoTracking().ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,6 +15,7 @@ namespace PerformanceTest.TestItems
|
||||
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试一次读取1条数据的速度");
|
||||
var eachCount = 1000;
|
||||
|
||||
@@ -28,6 +30,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -63,5 +68,20 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.TestList.AsNoTracking().Single(it=>it.Id==1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -13,6 +14,7 @@ namespace PerformanceTest.TestItems
|
||||
{
|
||||
public void Init(OrmType type)
|
||||
{
|
||||
Database.SetInitializer<EFContext>(null);
|
||||
Console.WriteLine("测试SQL查询的速度");
|
||||
var eachCount = 3000;
|
||||
|
||||
@@ -27,6 +29,9 @@ namespace PerformanceTest.TestItems
|
||||
case OrmType.Dapper:
|
||||
Dapper(eachCount);
|
||||
break;
|
||||
case OrmType.EF:
|
||||
EF(eachCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.Write("总计:" + (DateTime.Now - beginDate).TotalMilliseconds / 1000.0);
|
||||
@@ -59,5 +64,19 @@ namespace PerformanceTest.TestItems
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void EF(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "EF", () =>
|
||||
{
|
||||
using (EFContext conn = new EFContext(Config.connectionString))
|
||||
{
|
||||
var list = conn.Database.SqlQuery<Test>("select top 10 * from Test").ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user