SqlSugar/Src/Asp.Net/PerformanceTest/Program.cs

89 lines
2.6 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;
2017-09-21 14:22:23 +08:00
using PerformanceTest.TestItems;
2019-12-12 19:26:15 +08:00
using SqlSugar;
2017-09-21 13:52:52 +08:00
namespace PerformanceTest
{
class Program
{
2017-09-22 17:49:15 +08:00
2017-09-21 13:52:52 +08:00
/// <summary>
2017-09-22 17:49:15 +08:00
/// 注意注意注意注意注意:分开测试比较公平,并且请在Realse模式下启动程序SqlSugar直接引用的是项目
2017-09-21 13:52:52 +08:00
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
2019-12-12 19:26:15 +08:00
InitData();
2020-11-27 19:01:30 +08:00
var type = DemoType.GetById;
var ormType = OrmType.SqlSugar;
2017-09-22 18:13:04 +08:00
switch (type)
{
case DemoType.GetAll:
new TestGetAll().Init(ormType);
break;
case DemoType.GetById:
2017-09-22 18:17:00 +08:00
new TestGetById().Init(ormType);
2017-09-22 18:13:04 +08:00
break;
2017-09-22 18:17:00 +08:00
case DemoType.GetSql:
new TestGetSql().Init(ormType);
2017-09-22 18:13:04 +08:00
break;
2019-12-12 20:29:21 +08:00
case DemoType.Insert:
new TestInsert().Init(ormType);
break;
2020-11-27 19:01:30 +08:00
case DemoType.Like:
new TestLike().Init(ormType);
break;
2017-09-22 18:13:04 +08:00
default:
break;
}
2017-09-21 13:52:52 +08:00
Console.ReadKey();
}
2019-12-12 19:26:15 +08:00
private static void InitData()
{
SqlSugarClient conn = Config.GetSugarConn();
conn.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute;
conn.DbMaintenance.CreateDatabase();//创建库
conn.CodeFirst.InitTables<Test>();
List<Test> test = new List<Test>();
if (conn.Queryable<Test>().Count() < 100000)
{
Console.WriteLine("初始化数据");
for (int i = 0; i < 100000; i++)
{
test.Add(new Test()
{
F_Bool = true,
F_Byte = 0,
F_DateTime = DateTime.Now,
F_Decimal = 1,
F_Double = 11,
F_Float = 11,
F_Guid = Guid.Empty,
F_String = "abc",
F_Int16 = 1,
F_Int32 = 1,
F_Int64 = 1
});
}
}
conn.Insertable(test).ExecuteCommand();
}
2017-09-22 18:13:04 +08:00
enum DemoType
{
GetAll,
GetById,
2019-12-12 20:29:21 +08:00
GetSql,
2020-11-27 19:01:30 +08:00
Insert,
Like
2017-09-22 18:13:04 +08:00
}
2017-09-21 13:52:52 +08:00
}
}