Skip to content

Commit 906a66e

Browse files
committed
make sure the file reading and JSON parsing isn't part of the benchmarked code
1 parent 96d63cd commit 906a66e

File tree

1 file changed

+14
-40
lines changed

1 file changed

+14
-40
lines changed

Source/Tests/Plugins/DeduplicationBenchmarks.cs

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using BenchmarkDotNet.Attributes;
45
using Exceptionless.Extensions;
@@ -9,6 +10,12 @@
910

1011
namespace Exceptionless.Tests.Plugins {
1112
public class DeduplicationBenchmarks {
13+
private readonly List<Event> _events = new List<Event>();
14+
public DeduplicationBenchmarks() {
15+
foreach (var file in Directory.GetFiles(@"..\..\ErrorData", "*.json")) {
16+
_events.Add(GetEvent(file));
17+
}
18+
}
1219
protected virtual IJsonSerializer GetSerializer() {
1320
return new DefaultJsonSerializer();
1421
}
@@ -25,48 +32,15 @@ public void TestBenchmark1() {
2532
var errorPlugin = new ErrorPlugin();
2633
var duplicateCheckerPlugin = new DuplicateCheckerPlugin();
2734

28-
var ev = GetEvent(@"..\..\ErrorData\1.json");
29-
var pluginContextData = new ContextData();
30-
31-
for (int index = 0; index < 2; index++) {
32-
var context = new EventPluginContext(client, ev, pluginContextData);
33-
34-
errorPlugin.Run(context);
35-
duplicateCheckerPlugin.Run(context);
36-
}
37-
}
38-
39-
[Benchmark]
40-
public void TestBenchmark2() {
41-
var client = new ExceptionlessClient();
42-
var errorPlugin = new ErrorPlugin();
43-
var duplicateCheckerPlugin = new DuplicateCheckerPlugin();
44-
45-
var ev = GetEvent(@"..\..\ErrorData\2.json");
46-
var pluginContextData = new ContextData();
47-
48-
for (int index = 0; index < 2; index++) {
49-
var context = new EventPluginContext(client, ev, pluginContextData);
50-
51-
errorPlugin.Run(context);
52-
duplicateCheckerPlugin.Run(context);
53-
}
54-
}
55-
56-
[Benchmark]
57-
public void TestBenchmark3() {
58-
var client = new ExceptionlessClient();
59-
var errorPlugin = new ErrorPlugin();
60-
var duplicateCheckerPlugin = new DuplicateCheckerPlugin();
61-
62-
var ev = GetEvent(@"..\..\ErrorData\3.json");
63-
var pluginContextData = new ContextData();
35+
foreach (var ev in _events) {
36+
var pluginContextData = new ContextData();
6437

65-
for (int index = 0; index < 2; index++) {
66-
var context = new EventPluginContext(client, ev, pluginContextData);
38+
for (int index = 0; index < 2; index++) {
39+
var context = new EventPluginContext(client, ev, pluginContextData);
6740

68-
errorPlugin.Run(context);
69-
duplicateCheckerPlugin.Run(context);
41+
errorPlugin.Run(context);
42+
duplicateCheckerPlugin.Run(context);
43+
}
7044
}
7145
}
7246
}

0 commit comments

Comments
 (0)