Add performance test project

This commit is contained in:
sunkaixuan 2017-09-21 13:52:52 +08:00
parent 0620c3fdbb
commit b7e919999c
12 changed files with 378 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,54 @@
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

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace PerformanceTest.Items
{
/// <summary>
/// 性能测试类,用于循环执行代码并统计时间
/// </summary>
public class PerHelper
{
public static void Execute(int count, string title, Action fun)
{
SyntacticSugar.PerformanceTest ptef = new SyntacticSugar.PerformanceTest();
ptef.SetCount(count);//执行count次
ptef.Execute(
i =>
{
fun();
},
res =>
{
Console.WriteLine(string.Format("执行{0}次,{1}{2}", count, title, res));
});
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PerformanceTest.Items
{
public class PubConst
{
public static string connectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugarTest";
}
}

View File

@ -0,0 +1,65 @@
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
{
public class SelectBigData
{
/// <summary>
/// 测试一次读取100万条数据的速度
/// </summary>
public void Init()
{
Console.WriteLine("测试一次读取100万条数据的速度");
var eachCount = 1000;
/*******************车轮战是性能评估最准确的一种方式***********************/
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", () =>
{
using (SqlSugarClient conn = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.SystemTable, ConnectionString= PubConst.connectionString, DbType=DbType.SqlServer }))
{
// var list = conn.Ado.SqlQuery<Test>("select * from test where id=1");
var list2 = conn.Queryable<Test>().InSingle(1);
}
});
}
private static void Dapper(int eachCount)
{
GC.Collect();//回收资源
System.Threading.Thread.Sleep(1);//休息2秒
//正试比拼
PerHelper.Execute(eachCount, "Dapper", () =>
{
using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
{
var list = conn.Get<Test>(1);
}
});
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SqlSugar;
using Dapper;
using Dapper.Contrib;
using Dapper.Contrib.Extensions;
namespace PerformanceTest.Items
{
public class WarmUp
{
public WarmUp()
{
Console.WriteLine("开启预热");
Console.WriteLine("预热完毕");
Console.WriteLine("----------------比赛开始-------------------");
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PerformanceTest
{
[Dapper.Contrib.Extensions.Table("Test")]
public class Test
{
[Dapper.Contrib.Extensions.Key]
public int Id { get; set; }
public byte? F_Byte { get; set; }
public Int16? F_Int16 { get; set; }
public int? F_Int32 { get; set; }
public long? F_Int64 { get; set; }
public double? F_Double { get; set; }
public float? F_Float { get; set; }
public decimal? F_Decimal { get; set; }
public bool? F_Bool { get; set; }
public DateTime? F_DateTime { get; set; }
public Guid? F_Guid { get; set; }
public string F_String { get; set; }
}
}

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PerformanceTest</RootNamespace>
<AssemblyName>PerformanceTest</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapper, Version=1.50.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.1.50.4-alpha1-00070\lib\net451\Dapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapper.Contrib, Version=1.50.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.Contrib.1.50.0\lib\net45\Dapper.Contrib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SyntacticSugar">
<HintPath>..\SqliteTest\OtherDll\SyntacticSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Items\PerHelper.cs" />
<Compile Include="Items\PubConst.cs" />
<Compile Include="Items\SelectBigData.cs" />
<Compile Include="Items\WarmUp.cs" />
<Compile Include="Models\TestEntity.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<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>
<Name>SqlSugar</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerformanceTest.Items;
namespace PerformanceTest
{
class Program
{
/// <summary>
/// SqlSugar与Dapper的性能比较
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
WarmUp wu = new WarmUp();//预热处理
new SelectBigData().Init();
Console.ReadKey();
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PerformanceTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PerformanceTest")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//将 ComVisible 设置为 false 将使此程序集中的类型
//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("60d6aa62-93ed-4d02-80e4-6beb81766d3e")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapper" version="1.50.4-alpha1-00070" targetFramework="net452" />
<package id="Dapper.Contrib" version="1.50.0" targetFramework="net452" />
<package id="Dapper.Extension" version="1.0.0.1" targetFramework="net452" />
</packages>

View File

@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqliteTest", "SqliteTest\Sq
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OracleTest", "OracleTest\OracleTest.csproj", "{4177D054-D113-4F8A-9E01-642E072F9C87}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerformanceTest", "PerformanceTest\PerformanceTest.csproj", "{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{4177D054-D113-4F8A-9E01-642E072F9C87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4177D054-D113-4F8A-9E01-642E072F9C87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4177D054-D113-4F8A-9E01-642E072F9C87}.Release|Any CPU.Build.0 = Release|Any CPU
{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60D6AA62-93ED-4D02-80E4-6BEB81766D3E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE