mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
-
This commit is contained in:
parent
b82ebd4608
commit
a219c88872
@ -57,6 +57,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\PerHelper.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="TestItems\TestGetById.cs" />
|
||||
<Compile Include="TestItems\TestGetAll.cs" />
|
||||
<Compile Include="Models\TestEntity.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -11,9 +11,6 @@ namespace PerformanceTest.Items
|
||||
{
|
||||
public class TestGetAll
|
||||
{
|
||||
/// <summary>
|
||||
/// 测试一次读取100万条数据的速度
|
||||
/// </summary>
|
||||
public void Init()
|
||||
{
|
||||
Console.WriteLine("测试一次读取100万条数据的速度");
|
||||
@ -24,7 +21,6 @@ namespace PerformanceTest.Items
|
||||
SqlSugar(1);
|
||||
Console.WriteLine("预热完毕");
|
||||
|
||||
/*******************车轮战是性能评估最准确的一种方式***********************/
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
//dapper
|
||||
@ -39,7 +35,7 @@ namespace PerformanceTest.Items
|
||||
private static void SqlSugar(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息2秒
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
PerHelper.Execute(eachCount, "SqlSugar", () =>
|
||||
{
|
||||
@ -53,9 +49,8 @@ namespace PerformanceTest.Items
|
||||
private static void Dapper(int eachCount)
|
||||
{
|
||||
GC.Collect();//回收资源
|
||||
System.Threading.Thread.Sleep(1);//休息2秒
|
||||
System.Threading.Thread.Sleep(1);//休息1秒
|
||||
|
||||
//正试比拼
|
||||
PerHelper.Execute(eachCount, "Dapper", () =>
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(Config.connectionString))
|
||||
|
65
Src/Asp.Net/PerformanceTest/TestItems/TestGetById.cs
Normal file
65
Src/Asp.Net/PerformanceTest/TestItems/TestGetById.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Dapper.Contrib.Extensions;
|
||||
using PerformanceTest.Items;
|
||||
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 TestGetById
|
||||
{
|
||||
|
||||
public void Init()
|
||||
{
|
||||
Console.WriteLine("测试一次读取1条数据的速度");
|
||||
var eachCount = 1000;
|
||||
|
||||
Console.WriteLine("开启预热");
|
||||
Dapper(1);
|
||||
SqlSugar(1);
|
||||
Console.WriteLine("预热完毕");
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
//dapper
|
||||
Dapper(eachCount);
|
||||
|
||||
//sqlSugar
|
||||
SqlSugar(eachCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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.Queryable<Test>().ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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.GetAll<Test>();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user