-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarks.cs
84 lines (75 loc) · 3.65 KB
/
Benchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using NLog;
namespace nlog.loki.benchmark
{
// Run the benchmark with the following command line:
// dotnet run --configuration Release --framework net48 --runtimes net48 netcoreapp31 net60 --filter * --join
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class Program
{
// Prepare logger and logging statements
private Logger Logger;
private readonly string[] Users = new[] { "Corentin Altepe", "A", "B", "C", "D", "E", "F", "G", "H" };
private readonly string[] Destinations = new[] { "127.0.0.1:8475", "A", "B", "C", "D", "E", "F", "G", "H" };
private readonly Exception Exception = new("Ooops. Something went wrong!");
private readonly List<string> LoggingMessages = new() {
"4 error CS8400: Feature 'target-typed object creation' is not available in C# 8.0. Please use language version 9.0 or greater.",
"5 error CS8370: Feature 'target-typed object creation' is not available in C# 7.3. Please use language version 9.0 or greater.",
"6 error CS0246: The type or namespace name 'Logger' could not be found (are you missing a using directive or an assembly reference?)",
};
static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args);
[Params(4, 12, 100, 1_000, 10_000)]
public int NumberLogs;
private List<Action> LoggingStatements;
[GlobalSetup]
public void GlobalSetup()
{
LoggingStatements = new();
var i = 0;
while(i < NumberLogs) {
LoggingStatements.Add(() => Logger.Info("1 Receive message from {User} with destination {Destination}.", Users[i % Users.Length], Destinations[i % Destinations.Length]));
i++;
LoggingStatements.Add(() => Logger.Info("2 Receive message from {User} with destination {Destination}.", Users[i % Users.Length], Destinations[i % Destinations.Length]));
i++;
LoggingStatements.Add(() => Logger.Info("3 Receive message from {User} with destination {Destination}.", Users[i % Users.Length], Destinations[i % Destinations.Length]));
i++;
LoggingStatements.Add(() => Logger.Info(LoggingMessages[i % 3]));
i++;
}
}
[IterationSetup(Targets = new[] { nameof(Grpc) })]
public void IterationSetupGrpc()
{
Logger = LogManager.GetCurrentClassLogger();
LogManager.Configuration.LoggingRules.Clear();
LogManager.Configuration.LoggingRules.Add(new("*", LogLevel.Info, LogLevel.Fatal, LogManager.Configuration.FindTargetByName("lokigrpc")));
LogManager.ReconfigExistingLoggers();
}
[Benchmark]
public void Grpc()
{
foreach(var action in LoggingStatements)
action();
LogManager.Flush();
}
[IterationSetup(Targets = new[] { nameof(Http) })]
public void IterationSetupHttp()
{
Logger = LogManager.GetCurrentClassLogger();
LogManager.Configuration.LoggingRules.Clear();
LogManager.Configuration.LoggingRules.Add(new("*", LogLevel.Info, LogLevel.Fatal, LogManager.Configuration.FindTargetByName("lokihttp")));
LogManager.ReconfigExistingLoggers();
}
[Benchmark]
public void Http()
{
foreach(var action in LoggingStatements)
action();
LogManager.Flush();
}
}
}