forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial RC2 perf tests for MinLevel and ForContext
- Loading branch information
Showing
8 changed files
with
338 additions
and
2 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
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 |
---|---|---|
@@ -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!"); | ||
} | ||
} | ||
} | ||
} | ||
|
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,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>(); | ||
} | ||
} | ||
} |
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,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
18
test/Serilog.PerformanceTests/Serilog.PerformanceTests.xproj
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,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> |
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,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" | ||
] | ||
} | ||
} | ||
} |