SqlSugar/Src/Asp.Net/PerformanceTest/TestItems/TestGetAll.cs

69 lines
1.9 KiB
C#
Raw Normal View History

2017-09-21 13:52:52 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Dapper;
using SqlSugar;
using Dapper.Contrib.Extensions;
namespace PerformanceTest.Items
{
2017-09-21 14:15:16 +08:00
public class TestGetAll
2017-09-21 13:52:52 +08:00
{
/// <summary>
/// 测试一次读取100万条数据的速度
/// </summary>
public void Init()
{
Console.WriteLine("测试一次读取100万条数据的速度");
2017-09-21 14:15:16 +08:00
var eachCount = 1;
Console.WriteLine("开启预热");
Dapper(1);
SqlSugar(1);
Console.WriteLine("预热完毕");
2017-09-21 13:52:52 +08:00
/*******************车轮战是性能评估最准确的一种方式***********************/
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);//休息2秒
PerHelper.Execute(eachCount, "SqlSugar", () =>
{
2017-09-21 14:15:16 +08:00
using (SqlSugarClient conn = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.SystemTable, ConnectionString= Config.connectionString, DbType=DbType.SqlServer }))
2017-09-21 13:52:52 +08:00
{
2017-09-21 14:15:16 +08:00
var list2 = conn.Queryable<Test>().ToList();
2017-09-21 13:52:52 +08:00
}
});
}
private static void Dapper(int eachCount)
{
GC.Collect();//回收资源
System.Threading.Thread.Sleep(1);//休息2秒
//正试比拼
PerHelper.Execute(eachCount, "Dapper", () =>
{
2017-09-21 14:15:16 +08:00
using (SqlConnection conn = new SqlConnection(Config.connectionString))
2017-09-21 13:52:52 +08:00
{
2017-09-21 14:15:16 +08:00
var list = conn.GetAll<Test>();
2017-09-21 13:52:52 +08:00
}
});
}
}
}