Skip to content

Commit 62382f0

Browse files
committed
Adding recording benchmark
1 parent 8485512 commit 62382f0

9 files changed

Lines changed: 205 additions & 9 deletions
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
55
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="BenchmarkDotNet" publicKeyToken="aa0ca2f9092cefc4" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-0.9.7.0" newVersion="0.9.7.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
614
</configuration>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Linq;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Diagnostics.Windows;
4+
using BenchmarkDotNet.Jobs;
5+
6+
namespace HdrHistogram.Benchmarking
7+
{
8+
public class ExhuastiveJobWithMemoryDiagnosisConfig : ManualConfig
9+
{
10+
public ExhuastiveJobWithMemoryDiagnosisConfig()
11+
{
12+
Add(new MemoryDiagnoser());
13+
14+
var crossProduct = from jitter in new[] {Jit.LegacyJit, Jit.RyuJit}
15+
from platform in new[] {Platform.AnyCpu, Platform.X64, Platform.X86}
16+
//Lets not test old/unsupported frameworks.
17+
from framework in new[] { /*Framework.V40, Framework.V45, Framework.V451,*/ Framework.V452, /*Framework.V46, Framework.V461,*/ Framework.V462 }
18+
//from toolchain in new[] {Toolchain.}
19+
//Currently the project doesn't support Core or Mono
20+
from runtime in new[] {Runtime.Clr, /*Runtime.Core , Runtime.Mono*/}
21+
//where !(runtime == Runtime.Core && (jitter == Jit.LegacyJit || platform!=Platform.X64))
22+
select new Job()
23+
{
24+
Jit = jitter,
25+
Platform = platform,
26+
Framework = framework,
27+
Runtime = runtime
28+
};
29+
30+
Add(crossProduct.ToArray());
31+
}
32+
}
33+
}

src/HdrHistogram.Benchmarking/HdrHistogram.Benchmarking.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
</PropertyGroup>
3737
<ItemGroup>
3838
<Reference Include="BenchmarkDotNet, Version=0.9.7.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
39-
<HintPath>..\packages\BenchmarkDotNet.0.9.7\lib\net40\BenchmarkDotNet.dll</HintPath>
39+
<HintPath>..\packages\BenchmarkDotNet.0.9.7-beta\lib\net40\BenchmarkDotNet.dll</HintPath>
4040
<Private>True</Private>
4141
</Reference>
42-
<Reference Include="BenchmarkDotNet.Diagnostics.Windows, Version=0.9.7.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
43-
<HintPath>..\packages\BenchmarkDotNet.Diagnostics.Windows.0.9.7\lib\net40\BenchmarkDotNet.Diagnostics.Windows.dll</HintPath>
42+
<Reference Include="BenchmarkDotNet.Diagnostics.Windows, Version=0.9.6.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
43+
<HintPath>..\packages\BenchmarkDotNet.Diagnostics.Windows.0.9.6\lib\net40\BenchmarkDotNet.Diagnostics.Windows.dll</HintPath>
4444
<Private>True</Private>
4545
</Reference>
4646
<Reference Include="Microsoft.Diagnostics.Tracing.TraceEvent, Version=1.0.41.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -61,6 +61,7 @@
6161
<Compile Include="..\HdrHistogram\Utilities\Bitwise.cs">
6262
<Link>LeadingZeroCount\Bitwise.cs</Link>
6363
</Compile>
64+
<Compile Include="ExhuastiveJobWithMemoryDiagnosisConfig.cs" />
6465
<Compile Include="LeadingZeroCount\DeBruijn128Bits.cs" />
6566
<Compile Include="LeadingZeroCount\DeBruijn64Bits.cs" />
6667
<Compile Include="LeadingZeroCount\IfAndShift.cs" />
@@ -72,11 +73,19 @@
7273
<Compile Include="LeadingZeroCount\StringManipulation.cs" />
7374
<Compile Include="Program.cs" />
7475
<Compile Include="Properties\AssemblyInfo.cs" />
76+
<Compile Include="Recording\Recording32BitBenchmark.cs" />
77+
<Compile Include="WithMemoryDiagnosisConfig.cs" />
7578
</ItemGroup>
7679
<ItemGroup>
7780
<None Include="App.config" />
7881
<None Include="packages.config" />
7982
</ItemGroup>
83+
<ItemGroup>
84+
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">
85+
<Project>{655d9c4c-5bbd-4494-9828-ae427a1ddd01}</Project>
86+
<Name>HdrHistogram</Name>
87+
</ProjectReference>
88+
</ItemGroup>
8089
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8190
<Import Project="..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets" Condition="Exists('..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets')" />
8291
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/HdrHistogram.Benchmarking/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Running;
2-
using HdrHistogram.Benchmarking.LeadingZeroCount;
32

43
namespace HdrHistogram.Benchmarking
54
{
@@ -8,8 +7,9 @@ class Program
87
static void Main(string[] args)
98
{
109
var switcher = new BenchmarkSwitcher(new[] {
11-
typeof(LeadingZeroCount64BitBenchmark),
12-
typeof(LeadingZeroCount32BitBenchmark)
10+
typeof(LeadingZeroCount.LeadingZeroCount64BitBenchmark),
11+
typeof(LeadingZeroCount.LeadingZeroCount32BitBenchmark),
12+
typeof(Recording.Recording32BitBenchmark),
1313
});
1414
switcher.Run(args);
1515
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System.Linq;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace HdrHistogram.Benchmarking.Recording
5+
{
6+
[Config(typeof(ExhuastiveJobWithMemoryDiagnosisConfig))]
7+
public class Recording32BitBenchmark
8+
{
9+
private readonly long[] _testValues;
10+
private readonly LongHistogram _longHistogram;
11+
private readonly IntHistogram _intHistogram;
12+
private readonly ShortHistogram _shortHistogram;
13+
private readonly Recorder _longRecorder;
14+
private readonly Recorder _intRecorder;
15+
private readonly Recorder _shortRecorder;
16+
17+
public Recording32BitBenchmark()
18+
{
19+
//Create array of +ve numbers in the 'maxBit' bit range (i.e. 32 bit or 64bit)
20+
var highestTrackableValue = TimeStamp.Minutes(10);
21+
_testValues = Enumerable.Range(0, 32)
22+
.Select(exp => new { Value = 1L << exp, LZC = 63 - exp })
23+
.SelectMany(x => new[]
24+
{
25+
x.Value-1,
26+
x.Value,
27+
x.Value+1,
28+
})
29+
.Where(x => x > 0)
30+
.Where(x=>x< highestTrackableValue)
31+
.Distinct()
32+
.ToArray();
33+
34+
_longHistogram = new LongHistogram(highestTrackableValue, 3);
35+
_intHistogram = new IntHistogram(highestTrackableValue, 3);
36+
_shortHistogram = new ShortHistogram(highestTrackableValue, 3);
37+
38+
_longRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new LongHistogram(id, low, hi, sf));
39+
_intRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new IntHistogram(id, low, hi, sf));
40+
_shortRecorder = new Recorder(1, highestTrackableValue, 3, (id, low, hi, sf) => new ShortHistogram(id, low, hi, sf));
41+
}
42+
43+
[Benchmark(Baseline = true)]
44+
public long LongHistogramRecording()
45+
{
46+
long counter = 0L;
47+
for (int i = 0; i < _testValues.Length; i++)
48+
{
49+
var value = _testValues[i];
50+
_longHistogram.RecordValue(value);
51+
counter += value;
52+
}
53+
return counter;
54+
}
55+
56+
[Benchmark]
57+
public long IntHistogramRecording()
58+
{
59+
long counter = 0L;
60+
for (int i = 0; i < _testValues.Length; i++)
61+
{
62+
var value = _testValues[i];
63+
_intHistogram.RecordValue(value);
64+
counter += value;
65+
}
66+
return counter;
67+
}
68+
69+
[Benchmark]
70+
public long ShortHistogramRecording()
71+
{
72+
for (int i = 0; i < _testValues.Length; i++)
73+
{
74+
_shortHistogram.RecordValue(_testValues[i]);
75+
}
76+
return _shortHistogram.TotalCount;
77+
}
78+
79+
[Benchmark]
80+
public long LongRecorderRecording()
81+
{
82+
long counter = 0L;
83+
84+
for (int i = 0; i < _testValues.Length; i++)
85+
{
86+
var value = _testValues[i];
87+
_longRecorder.RecordValue(value);
88+
counter += value;
89+
}
90+
return counter;
91+
}
92+
93+
[Benchmark]
94+
public long IntRecorderRecording()
95+
{
96+
long counter = 0L;
97+
for (int i = 0; i < _testValues.Length; i++)
98+
{
99+
var value = _testValues[i];
100+
_intRecorder.RecordValue(value);
101+
counter += value;
102+
}
103+
return counter;
104+
}
105+
106+
[Benchmark]
107+
public long ShortRecorderRecording()
108+
{
109+
long counter = 0L;
110+
for (int i = 0; i < _testValues.Length; i++)
111+
{
112+
var value = _testValues[i];
113+
_shortRecorder.RecordValue(value);
114+
counter += value;
115+
}
116+
return counter;
117+
}
118+
}
119+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Diagnostics.Windows;
3+
4+
namespace HdrHistogram.Benchmarking
5+
{
6+
public class WithMemoryDiagnosisConfig : ManualConfig
7+
{
8+
public WithMemoryDiagnosisConfig()
9+
{
10+
Add(new MemoryDiagnoser());
11+
//Add(new InliningDiagnoser());
12+
}
13+
}
14+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="BenchmarkDotNet" version="0.9.7" targetFramework="net461" />
4-
<package id="BenchmarkDotNet.Diagnostics.Windows" version="0.9.7" targetFramework="net461" />
3+
<package id="BenchmarkDotNet" version="0.9.7-beta" targetFramework="net461" />
4+
<package id="BenchmarkDotNet.Diagnostics.Windows" version="0.9.6" targetFramework="net461" />
55
<package id="Microsoft.Diagnostics.Tracing.TraceEvent" version="1.0.41" targetFramework="net461" />
66
</packages>

src/HdrHistogram/IntHistogram.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public IntHistogram(long lowestTrackableValue, long highestTrackableValue, int n
6666
{
6767
_counts = new int[CountsArrayLength];
6868
}
69+
public IntHistogram(long instanceId, long lowestTrackableValue, long highestTrackableValue,
70+
int numberOfSignificantValueDigits)
71+
: base(instanceId, lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits)
72+
{
73+
_counts = new int[CountsArrayLength];
74+
}
75+
6976

7077

7178
/// <summary>

src/HdrHistogram/ShortHistogram.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public ShortHistogram(long lowestTrackableValue, long highestTrackableValue, int
6868
{
6969
_counts = new short[CountsArrayLength];
7070
}
71+
public ShortHistogram(long instanceId, long lowestTrackableValue, long highestTrackableValue,
72+
int numberOfSignificantValueDigits)
73+
: base(instanceId, lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits)
74+
{
75+
_counts = new short[CountsArrayLength];
76+
}
7177

7278
/// <summary>
7379
/// Gets the total number of recorded values.

0 commit comments

Comments
 (0)