Update demo

This commit is contained in:
skx 2019-12-12 19:26:15 +08:00
parent b67e52f1bd
commit 1034fef4bf
7 changed files with 44 additions and 62 deletions

View File

@ -8,7 +8,7 @@ namespace PerformanceTest
{
public class Config
{
public static string connectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugarTest";
public static string connectionString = "server=.;uid=sa;pwd=haosql;database=SqlSugarTest";
public static ConnectionConfig SugarConfig =new ConnectionConfig() { IsAutoCloseConnection=true,InitKeyType = InitKeyType.SystemTable, ConnectionString = Config.connectionString, DbType = DbType.SqlServer };
public static SqlSugarClient GetSugarConn()
{

View File

@ -1,54 +0,0 @@
CREATE TABLE [dbo].[Test](
[Id] [int] IDENTITY(1,1) NOT NULL,
[F_Byte] [tinyint] NULL,
[F_Int16] [smallint] NULL,
[F_Int32] [int] NULL,
[F_Int64] [bigint] NULL,
[F_Double] [float] NULL,
[F_Float] [real] NULL,
[F_Decimal] [decimal](18, 0) NULL,
[F_Bool] [bit] NULL,
[F_DateTime] [datetime] NULL,
[F_Guid] [uniqueidentifier] NULL,
[F_String] [nvarchar](100) NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
declare @i int = 0;
begin tran;
while(@i<=1000000)
begin
INSERT INTO [dbo].[Test]
([F_Byte]
,[F_Int16]
,[F_Int32]
,[F_Int64]
,[F_Double]
,[F_Float]
,[F_Decimal]
,[F_Bool]
,[F_DateTime]
,[F_Guid]
,[F_String])
VALUES
(1
,2
,@i
,@i
,@i
,@i
,@i
,@i%2
,GETDATE()
,NEWID()
,'Chloe' + CAST(@i AS nvarchar(1000))
)
set @i=@i+1;
end
commit;

View File

@ -11,6 +11,7 @@ namespace PerformanceTest
public class Test
{
[Dapper.Contrib.Extensions.Key]
[SqlSugar.SugarColumn(IsIdentity =true ,IsPrimaryKey =true)]
public int Id { get; set; }
public byte? F_Byte { get; set; }
public Int16? F_Int16 { get; set; }

View File

@ -49,8 +49,8 @@
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SyntacticSugar">
<HintPath>..\SqliteTest\OtherDll\SyntacticSugar.dll</HintPath>
<Reference Include="SyntacticSugar, Version=2.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SyntacticSugar.2.4.1\lib\net40\SyntacticSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
@ -78,9 +78,6 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Dabase\test.sql" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj">
<Project>{489bb790-226c-4fad-8d1e-51d72a7ff8e5}</Project>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerformanceTest.TestItems;
using SqlSugar;
namespace PerformanceTest
{
@ -15,7 +16,9 @@ namespace PerformanceTest
/// <param name="args"></param>
static void Main(string[] args)
{
var type = DemoType.GetAll;
InitData();
var type = DemoType.GetById;
var ormType = OrmType.Dapper;
switch (type)
{
@ -33,6 +36,40 @@ namespace PerformanceTest
}
Console.ReadKey();
}
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();
}
enum DemoType
{
GetAll,

View File

@ -15,7 +15,7 @@ namespace PerformanceTest.TestItems
public void Init(OrmType type)
{
Database.SetInitializer<EFContext>(null);
Console.WriteLine("测试一次读取100万条数据的速度");
Console.WriteLine("测试一次读取10万条数据的速度");
var eachCount = 1;
var beginDate = DateTime.Now;

View File

@ -4,4 +4,5 @@
<package id="Dapper.Contrib" version="1.50.0" targetFramework="net452" />
<package id="Dapper.Extension" version="1.0.0.1" targetFramework="net452" />
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="SyntacticSugar" version="2.4.1" targetFramework="net452" />
</packages>