Skip to content

Commit

Permalink
Renamed test files and added LogEvent and parsing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jun 11, 2016
1 parent 1f6bb21 commit a2c2f38
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Serilog.PerformanceTests
/// <summary>
/// From https://github.com/serilog/serilog/pull/750
/// </summary>
public class ForContext
public class ForContextTests
{
private ILogger log;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

Expand Down
28 changes: 19 additions & 9 deletions test/Serilog.PerformanceTests/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,43 @@ namespace Serilog.PerformanceTests
// TODO:

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

// 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>();
var context = BenchmarkRunner.Run<ForContextTests>();
}

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

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

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

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

// 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 Serilog.Parsing;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Xunit;

namespace Serilog.PerformanceTests
{
public class LogEventTests
{
List<LogEventProperty> _properties;
Exception _exception;
MessageTemplate _emptyMessageTemplate;

[Setup]
public void Setup()
{
_exception = new Exception("An Error");
_emptyMessageTemplate = new MessageTemplate(Enumerable.Empty<MessageTemplateToken>());
_properties = new List<LogEventProperty>();

var items = Enumerable.Range(0,1000);
foreach (var item in items)
{
var prop = new LogEventProperty(item.ToString(), new ScalarValue(item));
_properties.Add(prop);
}
}

[Benchmark(Baseline = true)]
public void Baseline()
{
var le = new LogEvent(DateTimeOffset.Now,
LogEventLevel.Information,
_exception,
_emptyMessageTemplate,
Enumerable.Empty<LogEventProperty>());
}

[Benchmark()]
public void LogEvent1000Properties()
{
var le = new LogEvent(DateTimeOffset.Now,
LogEventLevel.Information,
_exception,
_emptyMessageTemplate,
_properties);
}
}
}

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

// 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 Serilog.Parsing;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Xunit;

namespace Serilog.PerformanceTests
{
public class MessageTemplateParserTests
{
MessageTemplateParser _parser;
const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}";

[Setup]
public void Setup()
{
_parser = new MessageTemplateParser();
}

[Benchmark(Baseline = true)]
public void Baseline()
{
var template = _parser.Parse("");
}

[Benchmark]
public void DefaultConsoleOutputTemplate()
{
var template = _parser.Parse(DefaultConsoleOutputTemplate);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Serilog.PerformanceTests
{
public class MinimumLevel
public class MinimumLevelTests
{
private ILogger log;
private LoggingLevelSwitch levelSwitch;
Expand Down
3 changes: 2 additions & 1 deletion test/Serilog.PerformanceTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"System.Collections": "4.0.11-rc2-24027",
},
"imports": [
"dnxcore50",
Expand Down

0 comments on commit a2c2f38

Please sign in to comment.