Skip to content

Commit 81e0fdb

Browse files
committed
Merge pull request #28 from LeeCampbell/Benchmark
Benchmarks
2 parents a246fa2 + 17efb0d commit 81e0fdb

20 files changed

Lines changed: 801 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</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>
14+
</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+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>HdrHistogram.Benchmarking</RootNamespace>
11+
<AssemblyName>HdrHistogram.Benchmarking</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="BenchmarkDotNet, Version=0.9.7.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
39+
<HintPath>..\packages\BenchmarkDotNet.0.9.7-beta\lib\net40\BenchmarkDotNet.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
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>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Microsoft.Diagnostics.Tracing.TraceEvent, Version=1.0.41.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\lib\net40\Microsoft.Diagnostics.Tracing.TraceEvent.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core" />
52+
<Reference Include="System.Management" />
53+
<Reference Include="System.Xml.Linq" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="Microsoft.CSharp" />
56+
<Reference Include="System.Data" />
57+
<Reference Include="System.Net.Http" />
58+
<Reference Include="System.Xml" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Compile Include="..\HdrHistogram\Utilities\Bitwise.cs">
62+
<Link>LeadingZeroCount\Bitwise.cs</Link>
63+
</Compile>
64+
<Compile Include="ExhuastiveJobWithMemoryDiagnosisConfig.cs" />
65+
<Compile Include="LeadingZeroCount\DeBruijn128Bits.cs" />
66+
<Compile Include="LeadingZeroCount\DeBruijn64Bits.cs" />
67+
<Compile Include="LeadingZeroCount\IfAndShift.cs" />
68+
<Compile Include="LeadingZeroCount\LeadingZeroCount32BitBenchmark.cs" />
69+
<Compile Include="LeadingZeroCount\LeadingZeroCount64BitBenchmark.cs" />
70+
<Compile Include="LeadingZeroCount\LeadingZeroCountBenchmarkBase.cs" />
71+
<Compile Include="LeadingZeroCount\Magic32Bit.cs" />
72+
<Compile Include="LeadingZeroCount\MathLog.cs" />
73+
<Compile Include="LeadingZeroCount\StringManipulation.cs" />
74+
<Compile Include="Program.cs" />
75+
<Compile Include="Properties\AssemblyInfo.cs" />
76+
<Compile Include="Recording\Recording32BitBenchmark.cs" />
77+
<Compile Include="WithMemoryDiagnosisConfig.cs" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<None Include="App.config" />
81+
<None Include="packages.config" />
82+
</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>
89+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
90+
<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')" />
91+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
92+
<PropertyGroup>
93+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
94+
</PropertyGroup>
95+
<Error Condition="!Exists('..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets'))" />
96+
</Target>
97+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
98+
Other similar extension points exist, see Microsoft.Common.targets.
99+
<Target Name="BeforeBuild">
100+
</Target>
101+
<Target Name="AfterBuild">
102+
</Target>
103+
-->
104+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace HdrHistogram.Benchmarking.LeadingZeroCount
2+
{
3+
public static class DeBruijn128Bits
4+
{
5+
private static readonly int[] BitPatternToLog2 = new int[128] {
6+
0, // change to 1 if you want bitSize(0) = 1
7+
48, -1, -1, 31, -1, 15, 51, -1, 63, 5, -1, -1, -1, 19, -1,
8+
23, 28, -1, -1, -1, 40, 36, 46, -1, 13, -1, -1, -1, 34, -1, 58,
9+
-1, 60, 2, 43, 55, -1, -1, -1, 50, 62, 4, -1, 18, 27, -1, 39,
10+
45, -1, -1, 33, 57, -1, 1, 54, -1, 49, -1, 17, -1, -1, 32, -1,
11+
53, -1, 16, -1, -1, 52, -1, -1, -1, 64, 6, 7, 8, -1, 9, -1,
12+
-1, -1, 20, 10, -1, -1, 24, -1, 29, -1, -1, 21, -1, 11, -1, -1,
13+
41, -1, 25, 37, -1, 47, -1, 30, 14, -1, -1, -1, -1, 22, -1, -1,
14+
35, 12, -1, -1, -1, 59, 42, -1, -1, 61, 3, 26, 38, 44, -1, 56
15+
};
16+
17+
private const ulong Multiplicator = 0x6c04f118e9966f6bUL;
18+
19+
private static int BitSize(ulong v)
20+
{
21+
v |= v >> 1;
22+
v |= v >> 2;
23+
v |= v >> 4;
24+
v |= v >> 8;
25+
v |= v >> 16;
26+
v |= v >> 32;
27+
return BitPatternToLog2[(ulong)(v * Multiplicator) >> 57];
28+
}
29+
30+
public static int GetLeadingZeroCount(long value)
31+
{
32+
return 64 - BitSize((ulong)value);
33+
}
34+
}
35+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
namespace HdrHistogram.Benchmarking.LeadingZeroCount
2+
{
3+
public static class DeBruijn64Bits
4+
{
5+
private static readonly int[] BitPatternToLog2 = new int[64] {
6+
0, // change to 1 if you want bitSize(0) = 1
7+
1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
8+
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
9+
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
10+
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
11+
}; // table taken from http://chessprogramming.wikispaces.com/De+Bruijn+Sequence+Generator
12+
13+
private const ulong Multiplicator = 0x022fdd63cc95386dUL;
14+
15+
private static int BitSize(ulong v)
16+
{
17+
v |= v >> 1;
18+
v |= v >> 2;
19+
v |= v >> 4;
20+
v |= v >> 8;
21+
v |= v >> 16;
22+
v |= v >> 32;
23+
// at this point you could also use popcount to find the number of set bits.
24+
// That might well be faster than a lookup table because you prevent a
25+
// potential cache miss
26+
if (v == unchecked((ulong)-1)) return 64;
27+
v++;
28+
return BitPatternToLog2[(ulong)(v * Multiplicator) >> 58];
29+
}
30+
31+
public static int GetLeadingZeroCount(long value)
32+
{
33+
return 64 - BitSize((ulong)value);
34+
}
35+
}
36+
37+
public static class DeBruijn64BitsBitScanner
38+
{
39+
private const ulong Magic = 0x37E84A99DAE458F;
40+
41+
private static readonly int[] MagicTable =
42+
{
43+
0, 1, 17, 2, 18, 50, 3, 57,
44+
47, 19, 22, 51, 29, 4, 33, 58,
45+
15, 48, 20, 27, 25, 23, 52, 41,
46+
54, 30, 38, 5, 43, 34, 59, 8,
47+
63, 16, 49, 56, 46, 21, 28, 32,
48+
14, 26, 24, 40, 53, 37, 42, 7,
49+
62, 55, 45, 31, 13, 39, 36, 6,
50+
61, 44, 12, 35, 60, 11, 10, 9,
51+
};
52+
53+
public static int BitScanForward(ulong b)
54+
{
55+
return MagicTable[((ulong)((long)b & -(long)b) * Magic) >> 58];
56+
}
57+
58+
private static int BitScanReverse(ulong b)
59+
{
60+
b |= b >> 1;
61+
b |= b >> 2;
62+
b |= b >> 4;
63+
b |= b >> 8;
64+
b |= b >> 16;
65+
b |= b >> 32;
66+
b = b & ~(b >> 1);
67+
return MagicTable[b * Magic >> 58];
68+
}
69+
70+
public static int GetLeadingZeroCount(long value)
71+
{
72+
return 63 ^ BitScanReverse((ulong)value);
73+
}
74+
}
75+
76+
//https://chessprogramming.wikispaces.com/BitScan
77+
public static class DeBruijnMultiplication
78+
{
79+
private static readonly int[] Index64 = new int[64] {
80+
0, 47, 1, 56, 48, 27, 2, 60,
81+
57, 49, 41, 37, 28, 16, 3, 61,
82+
54, 58, 35, 52, 50, 42, 21, 44,
83+
38, 32, 29, 23, 17, 11, 4, 62,
84+
46, 55, 26, 59, 40, 36, 15, 53,
85+
34, 51, 20, 43, 31, 22, 10, 45,
86+
25, 39, 14, 33, 19, 30, 9, 24,
87+
13, 18, 8, 12, 7, 6, 5, 63
88+
};
89+
90+
/**
91+
* bitScanReverse
92+
* @authors Kim Walisch, Mark Dickinson
93+
* @param bb bitboard to scan
94+
* @precondition bb != 0
95+
* @return index (0..63) of most significant one bit
96+
*/
97+
private static int BitScanReverse(ulong bb)
98+
{
99+
const ulong debruijn64 = (0x03f79d71b4cb0a89);
100+
//assert(bb != 0);
101+
bb |= bb >> 1;
102+
bb |= bb >> 2;
103+
bb |= bb >> 4;
104+
bb |= bb >> 8;
105+
bb |= bb >> 16;
106+
bb |= bb >> 32;
107+
return Index64[(bb * debruijn64) >> 58];
108+
}
109+
public static int GetLeadingZeroCount(long value)
110+
{
111+
return 63 ^ BitScanReverse((ulong)value);
112+
}
113+
}
114+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace HdrHistogram.Benchmarking.LeadingZeroCount
2+
{
3+
//Can we optimise this impl for value between 1->long.max
4+
// i.e. not 0, not -ve and not values over 2^63 (ulong)
5+
public static class IfAndShift
6+
{
7+
8+
public static int GetLeadingZeroCount(long input)
9+
{
10+
return (int) CountLeadingZeros((ulong) input);
11+
}
12+
13+
//http://stackoverflow.com/questions/31374628/fast-way-of-finding-most-and-least-significant-bit-set-in-a-64-bit-integer?lq=1
14+
public static ulong CountLeadingZeros(ulong input)
15+
{
16+
if (input == 0) return 64;
17+
18+
ulong n = 1;
19+
20+
if ((input >> 32) == 0) { n = n + 32; input = input << 32; }
21+
if ((input >> 48) == 0) { n = n + 16; input = input << 16; }
22+
if ((input >> 56) == 0) { n = n + 8; input = input << 8; }
23+
if ((input >> 60) == 0) { n = n + 4; input = input << 4; }
24+
if ((input >> 62) == 0) { n = n + 2; input = input << 2; }
25+
n = n - (input >> 63);
26+
27+
return n;
28+
}
29+
}
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HdrHistogram.Benchmarking.LeadingZeroCount
2+
{
3+
public class LeadingZeroCount32BitBenchmark : LeadingZeroCountBenchmarkBase
4+
{
5+
public LeadingZeroCount32BitBenchmark()
6+
: base(32)
7+
{
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HdrHistogram.Benchmarking.LeadingZeroCount
2+
{
3+
public class LeadingZeroCount64BitBenchmark : LeadingZeroCountBenchmarkBase
4+
{
5+
public LeadingZeroCount64BitBenchmark()
6+
:base(64)
7+
{
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)