Skip to content

Commit

Permalink
Initial RC2 perf tests for MinLevel and ForContext
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jun 10, 2016
1 parent 2b54800 commit 01d3dff
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
BenchmarkDotNet.Artifacts/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
6 changes: 6 additions & 0 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ Push-Location test/Serilog.Tests
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location

Push-Location test/Serilog.PerformanceTests

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

Pop-Location
10 changes: 8 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ for path in src/*/project.json; do
dotnet build ${dirname} -c Release
done

for path in test/Serilog.Tests/project.json; do
# for path in test/Serilog.Tests/project.json; do
# dirname="$(dirname "${path}")"
# dotnet build ${dirname} -f netcoreapp1.0 -c Release
# dotnet test ${dirname} -f netcoreapp1.0 -c Release
# done

for path in test/Serilog.PerformanceTests/project.json; do
dirname="$(dirname "${path}")"
dotnet build ${dirname} -f netcoreapp1.0 -c Release
dotnet test ${dirname} -f netcoreapp1.0 -c Release
done
done
70 changes: 70 additions & 0 deletions test/Serilog.PerformanceTests/ForContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

namespace Serilog.PerformanceTests
{
/// <summary>
/// From https://github.com/serilog/serilog/pull/750
/// </summary>
public class ForContext
{
private ILogger log;

[Setup]
public void Setup()
{
log = new LoggerConfiguration()
.WriteTo.Sink(new DelegatingSink(e => { }))
.CreateLogger();
}

[Benchmark(Baseline = true)]
public void Baseline()
{
for (var i = 0; i < 10; ++i)
{
log.Information("Event!");
}
}

[Benchmark]
public void ForContextInfo10()
{
for (var i = 0; i < 10; ++i)
{
var ctx = log.ForContext("I", i);
ctx.Information("Event!");
}
}

[Benchmark]
public void ForContextInfo1000()
{
for (var i = 0; i < 1000; ++i)
{
var ctx = log.ForContext("I", i);
ctx.Information("Event!");
}
}
}
}

52 changes: 52 additions & 0 deletions test/Serilog.PerformanceTests/Harness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

// Perf logger off
// Perf level off - Debug -

// LogContext Push
// ctor logevent -
// message template parser perf
// property binding perf (Bind message template)

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

[Fact]
public void MinimumLevel()
{
var context = BenchmarkRunner.Run<MinimumLevel>();
}
}
}
152 changes: 152 additions & 0 deletions test/Serilog.PerformanceTests/MinimumLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

// Copyright 2013-2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

namespace Serilog.PerformanceTests
{
public class MinimumLevel
{
private ILogger log;
private LoggingLevelSwitch levelSwitch;

[Setup]
public void Setup()
{
levelSwitch = new LoggingLevelSwitch();
levelSwitch.MinimumLevel = LogEventLevel.Verbose;

log = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Sink(new DelegatingSink(e => { }))
.CreateLogger();
}

[Benchmark(Baseline = true)]
public void Baseline()
{
//By default this is info, set to verbose for baseline
for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumVerbose()
{
levelSwitch.MinimumLevel = LogEventLevel.Verbose;

for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumDebug()
{
levelSwitch.MinimumLevel = LogEventLevel.Debug;

for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumInfo()
{
levelSwitch.MinimumLevel = LogEventLevel.Information;
for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumWarn()
{
levelSwitch.MinimumLevel = LogEventLevel.Warning;
for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumError()
{
levelSwitch.MinimumLevel = LogEventLevel.Error;
for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}

[Benchmark]
public void MinimumFatal()
{
levelSwitch.MinimumLevel = LogEventLevel.Fatal;
for (var i = 0; i < 1000; ++i)
{
log.Verbose("A verbose event!");
log.Debug("A debug event!");
log.Information("An info event!");
log.Warning("A warm event!");
log.Error("An error event!");
log.Fatal("A fatal event!");
}
}
}
}

18 changes: 18 additions & 0 deletions test/Serilog.PerformanceTests/Serilog.PerformanceTests.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>d7a37f73-bba3-4dae-9648-1a753a86f968</ProjectGuid>
<RootNamespace>Serilog.PerformanceTests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
31 changes: 31 additions & 0 deletions test/Serilog.PerformanceTests/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"testRunner": "xunit",

"dependencies": {
"Serilog": { "target": "project" },
"Serilog.Tests": { "target": "project" },
"TestDummies": { "target": "project" },
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10015",
"BenchmarkDotNet": "0.9.7-beta"
},
"buildOptions": {
"keyFile": "../../assets/Serilog.snk"
},
"frameworks": {
"net4.5.2": {
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}

0 comments on commit 01d3dff

Please sign in to comment.