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

107 lines
3.4 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;
2021-02-01 21:33:53 +08:00
using PerformanceTest.Models;
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)
{
2021-02-01 21:33:53 +08:00
InitData();
2019-12-12 19:26:15 +08:00
2021-02-02 00:56:24 +08:00
var type = DemoType.OneToMany;
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;
2021-02-02 00:56:24 +08:00
case DemoType.OneToMany:
2021-02-01 21:33:53 +08:00
new TestOneToMany().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
});
}
}
2021-02-01 21:33:53 +08:00
conn.CodeFirst.InitTables<Group>();
2021-02-02 00:56:24 +08:00
// conn.DbMaintenance.TruncateTable<Group>();
2021-02-01 21:33:53 +08:00
conn.CodeFirst.InitTables<User>();
2021-02-02 00:56:24 +08:00
//conn.DbMaintenance.TruncateTable<User>();
if (conn.Queryable<Group>().Count() < 500)
{
for (int i = 0; i < 1000; i++)
{
conn.Insertable(new Group { Id = i, Name = i + Guid.NewGuid().ToString() }).ExecuteCommand();
conn.Insertable(new User() { AGroupId = i, Id = i + 1 }).ExecuteCommand();
conn.Insertable(new User() { AGroupId = i, Id = i + 200000 }).ExecuteCommand();
}
conn.Insertable(test).ExecuteCommand();
}
2019-12-12 19:26:15 +08:00
}
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,
2021-02-01 21:33:53 +08:00
Like,
2021-02-02 00:56:24 +08:00
OneToMany
2017-09-22 18:13:04 +08:00
}
2017-09-21 13:52:52 +08:00
}
}