-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks to compare performance against Microsoft Logging proposal ( …
- Loading branch information
Showing
5 changed files
with
157 additions
and
0 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
Binary file added
BIN
+9.83 KB
...nterpolatedLogging.Microsoft.Extensions.Logging.Tests/BenchmarkTests-Result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions
107
src/InterpolatedLogging.Microsoft.Extensions.Logging.Tests/BenchmarkTests.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,107 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Console; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using static InterpolatedLogging.NamedProperties; | ||
|
||
namespace InterpolatedLogging.Tests | ||
{ | ||
public class BenchmarkTests | ||
{ | ||
|
||
|
||
[Test] | ||
public void BenchmarkTest1() | ||
{ | ||
System.Diagnostics.Debug.WriteLine($"---------"); | ||
int iteractions = 100000; | ||
|
||
var fac = Microsoft.Extensions.Logging.LoggerFactory.Create((builder) => { builder.SetMinimumLevel(LogLevel.Debug).AddConsole(); }); | ||
var logger = new Microsoft.Extensions.Logging.Logger<int>(fac); | ||
|
||
// Microsoft Logging Generator ( https://github.com/geeknoid/LoggingGenerator ) | ||
var sw = Stopwatch.StartNew(); | ||
for (int i = 0; i < iteractions; i++) | ||
{ | ||
Log.CouldNotOpenSocket(logger, Environment.MachineName); | ||
} | ||
System.Diagnostics.Debug.WriteLine($"Microsoft Logging Generator (1 argument): {sw.ElapsedMilliseconds}ms"); | ||
|
||
// InterpolatedLogging | ||
sw = Stopwatch.StartNew(); | ||
for (int i = 0; i < iteractions; i++) | ||
{ | ||
logger.InterpolatedDebug($"Could not open socket to `{Environment.MachineName:hostName}`"); | ||
} | ||
System.Diagnostics.Debug.WriteLine($"InterpolatedLogging (1 argument): {sw.ElapsedMilliseconds}ms"); | ||
} | ||
|
||
[Test] | ||
public void BenchmarkTest2() | ||
{ | ||
System.Diagnostics.Debug.WriteLine($"---------"); | ||
int iteractions = 100000; | ||
|
||
var fac = Microsoft.Extensions.Logging.LoggerFactory.Create((builder) => { builder.SetMinimumLevel(LogLevel.Debug).AddConsole(); }); | ||
var logger = new Microsoft.Extensions.Logging.Logger<int>(fac); | ||
|
||
// Microsoft Logging Generator ( https://github.com/geeknoid/LoggingGenerator ) | ||
var sw = Stopwatch.StartNew(); | ||
for (int i = 0; i < iteractions; i++) | ||
{ | ||
Log.FourArgumentsLog(logger, Environment.MachineName, DateTime.Now, 10, true); | ||
} | ||
System.Diagnostics.Debug.WriteLine($"Microsoft Logging Generator (4 arguments): {sw.ElapsedMilliseconds}ms"); | ||
|
||
// InterpolatedLogging | ||
sw = Stopwatch.StartNew(); | ||
for (int i = 0; i < iteractions; i++) | ||
{ | ||
logger.InterpolatedDebug($"Could not open socket to `{Environment.MachineName:hostName}` at {DateTime.Now:Timestamp} with amount {10m:Amount} - flag is {true:Flag}"); | ||
} | ||
System.Diagnostics.Debug.WriteLine($"InterpolatedLogging (4 arguments): {sw.ElapsedMilliseconds}ms"); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
static partial class Log | ||
{ | ||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "1.0.0.0")] | ||
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, string, global::System.Exception> __CouldNotOpenSocketCallback = | ||
global::Microsoft.Extensions.Logging.LoggerMessage.Define<string>(global::Microsoft.Extensions.Logging.LogLevel.Critical, new global::Microsoft.Extensions.Logging.EventId(0, nameof(CouldNotOpenSocket)), "Could not open socket to `{hostName}`"); | ||
|
||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "1.0.0.0")] | ||
public static void CouldNotOpenSocket(Microsoft.Extensions.Logging.ILogger logger, string hostName) | ||
{ | ||
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Critical)) | ||
{ | ||
__CouldNotOpenSocketCallback(logger, hostName, null); | ||
} | ||
} | ||
|
||
|
||
|
||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "1.0.0.0")] | ||
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, string, DateTime, decimal, bool, global::System.Exception> _FourArgumentsCallback = | ||
global::Microsoft.Extensions.Logging.LoggerMessage.Define<string, DateTime, decimal, bool>(global::Microsoft.Extensions.Logging.LogLevel.Critical, new global::Microsoft.Extensions.Logging.EventId(0, nameof(CouldNotOpenSocket)), "Could not open socket to `{hostName}` at {Timestamp} with amount {Amount} - flag is {Flag}"); | ||
|
||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Extensions.Logging.Generators", "1.0.0.0")] | ||
public static void FourArgumentsLog(Microsoft.Extensions.Logging.ILogger logger, string hostName, DateTime now, decimal amount, bool flag) | ||
{ | ||
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Critical)) | ||
{ | ||
_FourArgumentsCallback(logger, hostName, now, amount, flag, null); | ||
} | ||
} | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ft.Extensions.Logging.Tests/InterpolatedLogging.Microsoft.Extensions.Logging.Tests.csproj
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<Company>Rick Drizin</Company> | ||
|
||
<Copyright>Rick Drizin</Copyright> | ||
|
||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
|
||
<PackageProjectUrl>https://github.com/Drizin/InterpolatedLogging/</PackageProjectUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-preview.1.21102.12" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" /> | ||
<PackageReference Include="Npgsql" Version="4.1.4" /> | ||
<PackageReference Include="nunit" Version="3.10.1" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" /> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\InterpolatedLogging.Microsoft.Extensions.Logging\InterpolatedLogging.Microsoft.Extensions.Logging.csproj" /> | ||
</ItemGroup> | ||
|
||
</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