Skip to content

Commit 899c9f7

Browse files
committed
Adding Concurrent benchmarks
1 parent 0f0fbdb commit 899c9f7

4 files changed

Lines changed: 79 additions & 3 deletions

File tree

src/HdrHistogram.Benchmarking/Recording/Recording32BitBenchmark.cs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ public class Recording32BitBenchmark
88
{
99
private readonly long[] _testValues;
1010
private readonly LongHistogram _longHistogram;
11+
private readonly LongConcurrentHistogram _longConcurrentHistogram;
1112
private readonly IntHistogram _intHistogram;
13+
private readonly IntConcurrentHistogram _intConcurrentHistogram;
1214
private readonly ShortHistogram _shortHistogram;
1315
private readonly Recorder _longRecorder;
16+
private readonly Recorder _longConcurrentRecorder;
1417
private readonly Recorder _intRecorder;
18+
private readonly Recorder _intConcurrentRecorder;
1519
private readonly Recorder _shortRecorder;
1620

1721
public Recording32BitBenchmark()
@@ -27,16 +31,21 @@ public Recording32BitBenchmark()
2731
x.Value+1,
2832
})
2933
.Where(x => x > 0)
30-
.Where(x=>x< highestTrackableValue)
34+
.Where(x => x < highestTrackableValue)
3135
.Distinct()
3236
.ToArray();
3337

3438
_longHistogram = new LongHistogram(highestTrackableValue, 3);
3539
_intHistogram = new IntHistogram(highestTrackableValue, 3);
3640
_shortHistogram = new ShortHistogram(highestTrackableValue, 3);
3741

42+
_longConcurrentHistogram = new LongConcurrentHistogram(1, highestTrackableValue, 3);
43+
_intConcurrentHistogram = new IntConcurrentHistogram(1, highestTrackableValue, 3);
44+
3845
_longRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new LongHistogram(id, low, hi, sf));
46+
_longConcurrentRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new LongConcurrentHistogram(id, low, hi, sf));
3947
_intRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new IntHistogram(id, low, hi, sf));
48+
_intConcurrentRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new IntConcurrentHistogram(id, low, hi, sf));
4049
_shortRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new ShortHistogram(id, low, hi, sf));
4150
}
4251

@@ -53,6 +62,19 @@ public long LongHistogramRecording()
5362
return counter;
5463
}
5564

65+
[Benchmark]
66+
public long LongConcurrentHistogramRecording()
67+
{
68+
long counter = 0L;
69+
for (int i = 0; i < _testValues.Length; i++)
70+
{
71+
var value = _testValues[i];
72+
_longConcurrentHistogram.RecordValue(value);
73+
counter += value;
74+
}
75+
return counter;
76+
}
77+
5678
[Benchmark]
5779
public long IntHistogramRecording()
5880
{
@@ -66,6 +88,19 @@ public long IntHistogramRecording()
6688
return counter;
6789
}
6890

91+
[Benchmark]
92+
public long IntConcurrentHistogramRecording()
93+
{
94+
long counter = 0L;
95+
for (int i = 0; i < _testValues.Length; i++)
96+
{
97+
var value = _testValues[i];
98+
_intConcurrentHistogram.RecordValue(value);
99+
counter += value;
100+
}
101+
return counter;
102+
}
103+
69104
[Benchmark]
70105
public long ShortHistogramRecording()
71106
{
@@ -90,6 +125,20 @@ public long LongRecorderRecording()
90125
return counter;
91126
}
92127

128+
[Benchmark]
129+
public long LongConcurrentRecorderRecording()
130+
{
131+
long counter = 0L;
132+
133+
for (int i = 0; i < _testValues.Length; i++)
134+
{
135+
var value = _testValues[i];
136+
_longConcurrentRecorder.RecordValue(value);
137+
counter += value;
138+
}
139+
return counter;
140+
}
141+
93142
[Benchmark]
94143
public long IntRecorderRecording()
95144
{
@@ -103,6 +152,19 @@ public long IntRecorderRecording()
103152
return counter;
104153
}
105154

155+
[Benchmark]
156+
public long IntConcurrentRecorderRecording()
157+
{
158+
long counter = 0L;
159+
for (int i = 0; i < _testValues.Length; i++)
160+
{
161+
var value = _testValues[i];
162+
_intConcurrentRecorder.RecordValue(value);
163+
counter += value;
164+
}
165+
return counter;
166+
}
167+
106168
[Benchmark]
107169
public long ShortRecorderRecording()
108170
{

src/HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@
7070
<Compile Include="Persistence\TestCaseGenerator.cs" />
7171
<Compile Include="Properties\AssemblyInfo.cs" />
7272
<Compile Include="Recording\RecorderTestsBase.cs" />
73-
<Compile Include="Recording\RecorderTestWithConcurrentHistogram.cs" />
73+
<Compile Include="Recording\RecorderTestWithIntConcurrentHistogram.cs" />
7474
<Compile Include="Recording\RecorderTestWithIntHistogram.cs" />
75+
<Compile Include="Recording\RecorderTestWithLongConcurrentHistogram.cs" />
7576
<Compile Include="Recording\RecorderTestWithLongHistogram.cs" />
7677
<Compile Include="Recording\RecorderTestWithLShortHistogram.cs" />
7778
<Compile Include="ShortHistogramTests.cs" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using NUnit.Framework;
2+
3+
namespace HdrHistogram.UnitTests.Recording
4+
{
5+
[TestFixture]
6+
public sealed class RecorderTestWithIntConcurrentHistogram : RecorderTestsBase
7+
{
8+
protected override HistogramBase Create(long id, long min, long max, int sf)
9+
{
10+
return new IntConcurrentHistogram(id, min, max, sf);
11+
}
12+
}
13+
}

src/HdrHistogram.UnitTests/Recording/RecorderTestWithConcurrentHistogram.cs renamed to src/HdrHistogram.UnitTests/Recording/RecorderTestWithLongConcurrentHistogram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace HdrHistogram.UnitTests.Recording
44
{
55
[TestFixture]
6-
public sealed class RecorderTestWithConcurrentHistogram : RecorderTestsBase
6+
public sealed class RecorderTestWithLongConcurrentHistogram : RecorderTestsBase
77
{
88
protected override HistogramBase Create(long id, long min, long max, int sf)
99
{

0 commit comments

Comments
 (0)