-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #578 from ckadluba/benchmark-tests
Added Benchmark.NET Performance Tests
- Loading branch information
Showing
10 changed files
with
173 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Performance Tests | ||
|
||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-and-perftest: | ||
runs-on: windows-latest # Build on Windows to ensure .NET Framework targets | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run build | ||
run: ./Build.ps1 -SkipTests | ||
shell: pwsh | ||
|
||
- name: Run performance tests | ||
run: ./RunPerfTests.ps1 | ||
shell: pwsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="6.0.1" /> | ||
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" /> | ||
<PackageVersion Include="System.Private.Uri" Version="4.3.2" /> | ||
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" /> | ||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" /> | ||
<PackageVersion Include="coverlet.collector" Version="3.2.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.7.0" /> | ||
<PackageVersion Include="Dapper.StrongName" Version="2.0.123" /> | ||
<PackageVersion Include="Moq" Version="4.18.2" /> | ||
<PackageVersion Include="xunit" Version="2.9.0" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" /> | ||
<PackageVersion Include="Serilog" Version="4.0.0" /> | ||
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" /> | ||
<PackageVersion Include="Serilog.Settings.Configuration" Version="3.4.0" /> | ||
</ItemGroup> | ||
</Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="6.0.1" /> | ||
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" /> | ||
<PackageVersion Include="System.Private.Uri" Version="4.3.2" /> | ||
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.6" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" /> | ||
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" /> | ||
<PackageVersion Include="coverlet.collector" Version="3.2.0" /> | ||
<PackageVersion Include="FluentAssertions" Version="6.7.0" /> | ||
<PackageVersion Include="Dapper.StrongName" Version="2.0.123" /> | ||
<PackageVersion Include="Moq" Version="4.18.2" /> | ||
<PackageVersion Include="xunit" Version="2.9.0" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" /> | ||
<PackageVersion Include="Serilog" Version="4.0.0" /> | ||
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" /> | ||
<PackageVersion Include="Serilog.Settings.Configuration" Version="3.4.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Push-Location $PSScriptRoot | ||
|
||
$artifactsPath = "$PSScriptRoot\artifacts\perftests" | ||
|
||
if (Test-Path "$artifactsPath") { | ||
echo "perf: Cleaning $artifactsPath" | ||
Remove-Item "$artifactsPath" -Force -Recurse | ||
} | ||
|
||
New-Item -Path "$artifactsPath" -ItemType Directory | ||
|
||
$perfTestProjectPath = "$PSScriptRoot/test/Serilog.Sinks.MSSqlServer.PerformanceTests" | ||
Push-Location "$perfTestProjectPath" | ||
|
||
echo "perf: Running performance test project in $perfTestProjectPath" | ||
& dotnet run -c Release | ||
|
||
cp ".\BenchmarkDotNet.Artifacts\results\*.*" "$artifactsPath\" | ||
Pop-Location | ||
|
||
Pop-Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/Serilog.Sinks.MSSqlServer.PerformanceTests/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Serilog.Sinks.MSSqlServer.PerformanceTests; | ||
|
||
/// <summary> | ||
/// Wrappers that make it easy to run benchmark suites through the <c>dotnet test</c> runner. | ||
/// </summary> | ||
/// <example> | ||
/// <code>dotnet test -c Release --filter "FullyQualifiedName=Serilog.Sinks.MSSqlServer.PerformanceTests.Harness.Pipeline"</code> | ||
/// </example> | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
BenchmarkRunner.Run<SinkBenchmarks>(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ilog.Sinks.MSSqlServer.PerformanceTests/Serilog.Sinks.MSSqlServer.PerformanceTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<AssemblyName>Serilog.Sinks.MSSqlServer.PerformanceTests</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<RuntimeIdentifiers>win</RuntimeIdentifiers> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<AnalysisLevel>6.0-recommended</AnalysisLevel> | ||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Serilog.Sinks.MSSqlServer\Serilog.Sinks.MSSqlServer.csproj"/> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
</ItemGroup> | ||
|
||
</Project> |
46 changes: 46 additions & 0 deletions
46
test/Serilog.Sinks.MSSqlServer.PerformanceTests/SinkBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Serilog.Sinks.MSSqlServer.PerformanceTests; | ||
|
||
[MemoryDiagnoser] | ||
public class SinkBenchmarks | ||
{ | ||
private const string _connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Database=LogTest;Integrated Security=SSPI;Encrypt=False;"; | ||
private const string _schemaName = "dbo"; | ||
private const string _tableName = "LogEvents"; | ||
private ILogger _log = null!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var options = new ColumnOptions(); | ||
options.Store.Add(StandardColumn.LogEvent); | ||
_log = new LoggerConfiguration() | ||
.WriteTo.MSSqlServer(_connectionString, | ||
sinkOptions: new MSSqlServerSinkOptions | ||
{ | ||
TableName = _tableName, | ||
SchemaName = _schemaName, | ||
AutoCreateSqlTable = true, | ||
AutoCreateSqlDatabase = true | ||
}, | ||
appConfiguration: null, | ||
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose, | ||
formatProvider: null, | ||
columnOptions: options, | ||
columnOptionsSection: null) | ||
.CreateLogger(); | ||
} | ||
|
||
[Benchmark] | ||
public void EmitLogEvent() | ||
{ | ||
_log.Information("Hello, {Name}!", "World"); | ||
} | ||
|
||
[Benchmark] | ||
public void IntProperties() | ||
{ | ||
_log.Information("Hello, {A} {B} {C}!", 1, 2, 3); | ||
} | ||
} |