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.
Renamed test files and added LogEvent and parsing tests.
- Loading branch information
Showing
7 changed files
with
150 additions
and
13 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,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
54
test/Serilog.PerformanceTests/MessageTemplateParserTests.cs
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,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); | ||
} | ||
} | ||
} | ||
|
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