Skip to content

Commit

Permalink
Added FromLogContext PushProperty.
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jun 10, 2016
1 parent 01d3dff commit 1f6bb21
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
6 changes: 0 additions & 6 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ 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: 10 additions & 0 deletions test/Serilog.PerformanceTests/ForContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public void ForContextInfo1000()
ctx.Information("Event!");
}
}

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

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

// 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.Context;
using System;
using Xunit;

namespace Serilog.PerformanceTests
{
public class FromLogContextPushProperty
{
private ILogger log;

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

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

[Benchmark]
public void Push1Property1000()
{
for (var i = 0; i < 1000; ++i)
{
using (LogContext.PushProperty("A", 2))
{
log.Information("Event!");
}
}
}

[Benchmark]
public void Push1Property10000()
{
for (var i = 0; i < 10000; ++i)
{
using (LogContext.PushProperty("A", 2))
{
log.Information("Event!");
}
}
}

[Benchmark]
public void Push2Properties1000()
{
for (var i = 0; i < 1000; ++i)
{
using (LogContext.PushProperty("A", 2))
using (LogContext.PushProperty("B", 1))
{
log.Information("Event!");
}
}
}

[Benchmark]
public void Push2Properties10000()
{
for (var i = 0; i < 10000; ++i)
{
using (LogContext.PushProperty("A", 2))
using (LogContext.PushProperty("B", 1))
{
log.Information("Event!");
}
}
}
}
}

6 changes: 6 additions & 0 deletions test/Serilog.PerformanceTests/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ public void MinimumLevel()
{
var context = BenchmarkRunner.Run<MinimumLevel>();
}

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

0 comments on commit 1f6bb21

Please sign in to comment.