mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
-
This commit is contained in:
parent
146a83abdf
commit
05819eb304
14
Src/Asp.Net/PerformanceTest/Common/OrmType.cs
Normal file
14
Src/Asp.Net/PerformanceTest/Common/OrmType.cs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -55,6 +55,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Common\OrmType.cs" />
|
||||||
<Compile Include="Common\PerHelper.cs" />
|
<Compile Include="Common\PerHelper.cs" />
|
||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
<Compile Include="TestItems\TestGetById.cs" />
|
<Compile Include="TestItems\TestGetById.cs" />
|
||||||
@ -62,6 +63,7 @@
|
|||||||
<Compile Include="Models\TestEntity.cs" />
|
<Compile Include="Models\TestEntity.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="TestItems\TestSql.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
@ -10,13 +10,14 @@ namespace PerformanceTest
|
|||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SqlSugar与Dapper的性能比较
|
/// 分开测试比较公平
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//new TestGetAll().Init();
|
//new TestGetAll().Init();
|
||||||
new TestGetById().Init();
|
//new TestGetById().Init();
|
||||||
|
new TestSql().Init(OrmType.SqlSugar);
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
Src/Asp.Net/PerformanceTest/TestItems/TestSql.cs
Normal file
64
Src/Asp.Net/PerformanceTest/TestItems/TestSql.cs
Normal file
@ -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<Test>("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<Test>("select top 10 * from Test");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user