Skip to content

Commit

Permalink
Updated (micro) benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Aug 19, 2016
1 parent ffb7ce4 commit bc44501
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 457 deletions.
21 changes: 8 additions & 13 deletions RunPerfTests.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
./Build.ps1

& dotnet restore
foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
echo "perf: Running performance test project in $test"

Push-Location src/Serilog
& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

& dotnet build -c Release -o ..\..\.\artifacts --version-suffix=$revision
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
Push-Location test/Serilog.PerformanceTests

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
Pop-Location
}

Pop-Location
Pop-Location
5 changes: 4 additions & 1 deletion Serilog.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
EndProject
Expand All @@ -12,10 +12,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5
.editorconfig = .editorconfig
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
build.sh = build.sh
CHANGES.md = CHANGES.md
global.json = global.json
NuGet.config = NuGet.config
README.md = README.md
run_perf_tests.sh = run_perf_tests.sh
RunPerfTests.ps1 = RunPerfTests.ps1
assets\Serilog.snk = assets\Serilog.snk
EndProjectSection
EndProject
Expand Down
80 changes: 0 additions & 80 deletions test/Serilog.PerformanceTests/ForContextTests.cs

This file was deleted.

99 changes: 0 additions & 99 deletions test/Serilog.PerformanceTests/FromLogContextPushPropertyTests.cs

This file was deleted.

39 changes: 17 additions & 22 deletions test/Serilog.PerformanceTests/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,49 @@

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Serilog.Tests.Support;
using Serilog;
using Serilog.Events;
using System;
using Xunit;

namespace Serilog.PerformanceTests
{
// TODO:

// For Context
// MinimumLevel
// Push - ForContext
// Ctor of LogEvent
// Message Template parsing

// property binding perf (Bind message template)

public class Runner
public class Harness
{
[Fact]
public void ForContext()
public void LogContextEnrichment()
{
var context = BenchmarkRunner.Run<ForContextTests>();
BenchmarkRunner.Run<LogContextEnrichmentBenchmark>();
}

[Fact]
public void MinimumLevel()
public void MessageTemplateParsing()
{
var context = BenchmarkRunner.Run<MinimumLevelTests>();
BenchmarkRunner.Run<MessageTemplateParsingBenchmark>();
}

[Fact]
public void FromLogContextPushProperty()
public void LevelControl()
{
BenchmarkRunner.Run<LevelControlBenchmark>();
}

[Fact]
public void NestedLoggerCreation()
{
var context = BenchmarkRunner.Run<FromLogContextPushPropertyTests>();
BenchmarkRunner.Run<NestedLoggerCreationBenchmark>();
}

[Fact]
public void LogEvent()
public void NestedLoggerLatency()
{
var context = BenchmarkRunner.Run<LogEventTests>();
BenchmarkRunner.Run<NestedLoggerLatencyBenchmark>();
}

[Fact]
public void MessageTemplateParser()
public void Pipeline()
{
var context = BenchmarkRunner.Run<MessageTemplateParserTests>();
BenchmarkRunner.Run<PipelineBenchmark>();
}
}
}
66 changes: 66 additions & 0 deletions test/Serilog.PerformanceTests/LevelControlBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System;
using Serilog.PerformanceTests.Support;
using Xunit;

namespace Serilog.PerformanceTests
{
/// <summary>
/// Tests the overhead of determining the active logging level.
/// </summary>
public class LevelControlBenchmark
{
ILogger _off, _levelSwitchOff, _minLevel, _levelSwitch;
readonly LogEvent _event = Some.InformationEvent();

[Setup]
public void Setup()
{
_off = new LoggerConfiguration()
.MinimumLevel.Fatal()
.WriteTo.Sink(new NullSink())
.CreateLogger();
_levelSwitchOff = new LoggerConfiguration()
.MinimumLevel.ControlledBy(new LoggingLevelSwitch(LogEventLevel.Fatal))
.WriteTo.Sink(new NullSink())
.CreateLogger();
_minLevel = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Sink(new NullSink())
.CreateLogger();
_levelSwitch = new LoggerConfiguration()
.MinimumLevel.ControlledBy(new LoggingLevelSwitch(LogEventLevel.Information))
.WriteTo.Sink(new NullSink())
.CreateLogger();
}

[Benchmark(Baseline = true)]
public void Off()
{
_off.Write(_event);
}

[Benchmark]
public void LevelSwitchOff()
{
_levelSwitchOff.Write(_event);
}

[Benchmark]
public void MinimumLevelOn()
{
_minLevel.Write(_event);
}

[Benchmark]
public void LevelSwitchOn()
{
_levelSwitch.Write(_event);
}
}
}

Loading

0 comments on commit bc44501

Please sign in to comment.