This commit is contained in:
sunkaixuan 2017-09-21 14:36:05 +08:00
parent 146a83abdf
commit 05819eb304
4 changed files with 83 additions and 2 deletions

View 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
}
}

View File

@ -55,6 +55,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\OrmType.cs" />
<Compile Include="Common\PerHelper.cs" />
<Compile Include="Config.cs" />
<Compile Include="TestItems\TestGetById.cs" />
@ -62,6 +63,7 @@
<Compile Include="Models\TestEntity.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestItems\TestSql.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View File

@ -10,13 +10,14 @@ namespace PerformanceTest
{
/// <summary>
/// SqlSugar与Dapper的性能比较
/// 分开测试比较公平
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
//new TestGetAll().Init();
new TestGetById().Init();
//new TestGetById().Init();
new TestSql().Init(OrmType.SqlSugar);
Console.ReadKey();
}
}

View 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");
}
});
}
}
}