diff --git a/Src/Asp.Net/PerformanceTest/Common/OrmType.cs b/Src/Asp.Net/PerformanceTest/Common/OrmType.cs
new file mode 100644
index 000000000..4199a0e02
--- /dev/null
+++ b/Src/Asp.Net/PerformanceTest/Common/OrmType.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PerformanceTest
+{
+ public enum OrmType
+ {
+ SqlSugar,
+ Dapper
+ }
+}
diff --git a/Src/Asp.Net/PerformanceTest/PerformanceTest.csproj b/Src/Asp.Net/PerformanceTest/PerformanceTest.csproj
index e0e33722b..a104f2d1b 100644
--- a/Src/Asp.Net/PerformanceTest/PerformanceTest.csproj
+++ b/Src/Asp.Net/PerformanceTest/PerformanceTest.csproj
@@ -55,6 +55,7 @@
+
@@ -62,6 +63,7 @@
+
diff --git a/Src/Asp.Net/PerformanceTest/Program.cs b/Src/Asp.Net/PerformanceTest/Program.cs
index 368e27ff9..31ee03ea0 100644
--- a/Src/Asp.Net/PerformanceTest/Program.cs
+++ b/Src/Asp.Net/PerformanceTest/Program.cs
@@ -10,13 +10,14 @@ namespace PerformanceTest
{
///
- /// SqlSugar与Dapper的性能比较
+ /// 分开测试比较公平
///
///
static void Main(string[] args)
{
//new TestGetAll().Init();
- new TestGetById().Init();
+ //new TestGetById().Init();
+ new TestSql().Init(OrmType.SqlSugar);
Console.ReadKey();
}
}
diff --git a/Src/Asp.Net/PerformanceTest/TestItems/TestSql.cs b/Src/Asp.Net/PerformanceTest/TestItems/TestSql.cs
new file mode 100644
index 000000000..80339301a
--- /dev/null
+++ b/Src/Asp.Net/PerformanceTest/TestItems/TestSql.cs
@@ -0,0 +1,64 @@
+using Dapper;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PerformanceTest.TestItems
+{
+ public class TestSql
+ {
+ public void Init(OrmType type)
+ {
+ Console.WriteLine("测试SQL查询的速度");
+ var eachCount = 3000;
+
+ for (int i = 0; i < 10; i++)
+ {
+ switch (type)
+ {
+ case OrmType.SqlSugar:
+ //sqlSugar
+ SqlSugar(eachCount);
+ break;
+ case OrmType.Dapper:
+ //dapper
+ Dapper(eachCount);
+ break;
+ }
+ }
+
+ }
+
+ private static void SqlSugar(int eachCount)
+ {
+ GC.Collect();//回收资源
+ System.Threading.Thread.Sleep(1);//休息1秒
+
+ PerHelper.Execute(eachCount, "SqlSugar", () =>
+ {
+ using (SqlSugarClient conn = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.SystemTable, ConnectionString = Config.connectionString, DbType = DbType.SqlServer }))
+ {
+ var list2 = conn.Ado.SqlQuery("select top 10 * from Test"); ;
+ }
+ });
+ }
+
+ private static void Dapper(int eachCount)
+ {
+ GC.Collect();//回收资源
+ System.Threading.Thread.Sleep(1);//休息1秒
+
+ PerHelper.Execute(eachCount, "Dapper", () =>
+ {
+ using (SqlConnection conn = new SqlConnection(Config.connectionString))
+ {
+ var list = conn.Query("select top 10 * from Test");
+ }
+ });
+ }
+ }
+}