This commit is contained in:
Lee Campbell 2017-06-03 07:18:30 +08:00
Родитель 3e7ad9d4eb
Коммит b94950dc47
59 изменённых файлов: 851 добавлений и 1210 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -1,6 +1,7 @@
gh-pages
Working/
build/runbuild.txt
BenchmarkDotNet.Artifacts/
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/

Просмотреть файл

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="BenchmarkDotNet" publicKeyToken="aa0ca2f9092cefc4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.9.7.0" newVersion="0.9.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Просмотреть файл

@ -1,33 +0,0 @@
using System.Linq;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Jobs;
namespace HdrHistogram.Benchmarking
{
public class ExhuastiveJobWithMemoryDiagnosisConfig : ManualConfig
{
public ExhuastiveJobWithMemoryDiagnosisConfig()
{
Add(new MemoryDiagnoser());
var crossProduct = from jitter in new[] {Jit.LegacyJit, Jit.RyuJit}
from platform in new[] {/*Platform.AnyCpu,*/ Platform.X64, Platform.X86}
//Lets not test old/unsupported frameworks.
from framework in new[] { /*Framework.V40, Framework.V45, Framework.V451, Framework.V452, Framework.V46, Framework.V461,*/ Framework.V462 }
//from toolchain in new[] {Toolchain.}
//Currently the project doesn't support Core or Mono
from runtime in new[] {Runtime.Clr, /*Runtime.Core , Runtime.Mono*/}
//where !(runtime == Runtime.Core && (jitter == Jit.LegacyJit || platform!=Platform.X64))
select new Job()
{
Jit = jitter,
Platform = platform,
Framework = framework,
Runtime = runtime
};
Add(crossProduct.ToArray());
}
}
}

Просмотреть файл

@ -1,104 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HdrHistogram.Benchmarking</RootNamespace>
<AssemblyName>HdrHistogram.Benchmarking</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworks>net47;netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Reference Include="BenchmarkDotNet, Version=0.9.7.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
<HintPath>..\packages\BenchmarkDotNet.0.9.7-beta\lib\net40\BenchmarkDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="BenchmarkDotNet.Diagnostics.Windows, Version=0.9.6.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
<HintPath>..\packages\BenchmarkDotNet.Diagnostics.Windows.0.9.6\lib\net40\BenchmarkDotNet.Diagnostics.Windows.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Diagnostics.Tracing.TraceEvent, Version=1.0.41.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\lib\net40\Microsoft.Diagnostics.Tracing.TraceEvent.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.6" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net47'">
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows">
<Version>0.10.6</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\HdrHistogram\Utilities\Bitwise.cs">
<Link>LeadingZeroCount\Bitwise.cs</Link>
</Compile>
<Compile Include="ExhuastiveJobWithMemoryDiagnosisConfig.cs" />
<Compile Include="LeadingZeroCount\DeBruijn128Bits.cs" />
<Compile Include="LeadingZeroCount\DeBruijn64Bits.cs" />
<Compile Include="LeadingZeroCount\IfAndShift.cs" />
<Compile Include="LeadingZeroCount\LeadingZeroCount32BitBenchmark.cs" />
<Compile Include="LeadingZeroCount\LeadingZeroCount64BitBenchmark.cs" />
<Compile Include="LeadingZeroCount\LeadingZeroCountBenchmarkBase.cs" />
<Compile Include="LeadingZeroCount\Magic32Bit.cs" />
<Compile Include="LeadingZeroCount\MathLog.cs" />
<Compile Include="LeadingZeroCount\StringManipulation.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Recording\Recording32BitBenchmark.cs" />
<Compile Include="WithMemoryDiagnosisConfig.cs" />
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">
<Project>{655d9c4c-5bbd-4494-9828-ae427a1ddd01}</Project>
<Name>HdrHistogram</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<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')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,4 +1,8 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
namespace HdrHistogram.Benchmarking
{
@ -6,12 +10,21 @@ namespace HdrHistogram.Benchmarking
{
static void Main(string[] args)
{
var manualConfig = ManualConfig.Create(DefaultConfig.Instance);
manualConfig.Add(new MemoryDiagnoser());
//manualConfig.Add(new BenchmarkDotNet.Diagnostics.Windows.InliningDiagnoser());
//manualConfig.Add(HardwareCounter.BranchMispredictions, HardwareCounter.BranchInstructions);
var config = manualConfig
.With(Job.Clr.With(Jit.LegacyJit))
.With(Job.Clr.With(Jit.RyuJit))
.With(Job.Core.With(Jit.RyuJit));
var switcher = new BenchmarkSwitcher(new[] {
typeof(LeadingZeroCount.LeadingZeroCount64BitBenchmark),
typeof(LeadingZeroCount.LeadingZeroCount32BitBenchmark),
typeof(Recording.Recording32BitBenchmark),
});
switcher.Run(args);
switcher.Run(args, config);
}
}
}

Просмотреть файл

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HdrHistogram.Benchmarking")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HdrHistogram.Benchmarking")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8aae86be-5abc-4902-b48b-20dcdbb93c7b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -3,7 +3,6 @@ using BenchmarkDotNet.Attributes;
namespace HdrHistogram.Benchmarking.Recording
{
[Config(typeof(ExhuastiveJobWithMemoryDiagnosisConfig))]
public class Recording32BitBenchmark
{
private readonly long[] _testValues;

Просмотреть файл

@ -1,14 +0,0 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
namespace HdrHistogram.Benchmarking
{
public class WithMemoryDiagnosisConfig : ManualConfig
{
public WithMemoryDiagnosisConfig()
{
Add(new MemoryDiagnoser());
//Add(new InliningDiagnoser());
}
}
}

Просмотреть файл

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BenchmarkDotNet" version="0.9.7-beta" targetFramework="net461" />
<package id="BenchmarkDotNet.Diagnostics.Windows" version="0.9.6" targetFramework="net461" />
<package id="Microsoft.Diagnostics.Tracing.TraceEvent" version="1.0.41" targetFramework="net461" />
</packages>

Просмотреть файл

@ -1,67 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E210C748-4792-4658-9345-CC073C29EC0B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HdrHistogram.Examples</RootNamespace>
<AssemblyName>HdrHistogram.Examples</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecorderExample.cs" />
<Compile Include="SimpleHistogramExample.cs" />
<Compile Include="SocketTester.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">
<Project>{655d9c4c-5bbd-4494-9828-ae427a1ddd01}</Project>
<Name>HdrHistogram</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HdrHistogram.Examples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HdrHistogram.Examples")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9ac83cb7-97da-49e4-a340-348a12ef3086")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]

Просмотреть файл

@ -84,13 +84,13 @@ namespace HdrHistogram.Examples
}
finally
{
_socket.Close();
_socket.Dispose();
}
}
private static AddressFamily GetAddressFamily(string url)
{
var hostIpAddress = Dns.GetHostEntry(url).AddressList[0];
var hostIpAddress = Dns.GetHostEntryAsync(url).GetAwaiter().GetResult().AddressList[0];
var hostIpEndPoint = new IPEndPoint(hostIpAddress, 80);
return hostIpEndPoint.AddressFamily;
}

Просмотреть файл

@ -31,7 +31,7 @@ namespace HdrHistogram.Examples
private static AddressFamily GetAddressFamily(string url)
{
var hostIpAddress = Dns.GetHostEntry(url).AddressList[0];
var hostIpAddress = Dns.GetHostEntryAsync(url).GetAwaiter().GetResult().AddressList[0];
var hostIpEndPoint = new IPEndPoint(hostIpAddress, 80);
return hostIpEndPoint.AddressFamily;
}

Просмотреть файл

@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

Просмотреть файл

@ -1,13 +1,13 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
public abstract class ConcurrentHistogramTestBase : HistogramTestBase
{
[Test]
[Fact]
public void Can_support_multiple_concurrent_recorders()
{
var target = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -25,7 +25,7 @@ namespace HdrHistogram.UnitTests
.ToArray();
Parallel.Invoke(actions);
Assert.AreEqual(expected, target.TotalCount);
Assert.Equal(expected, target.TotalCount);
}
}
}

Просмотреть файл

@ -1,143 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2D189069-FE39-42AE-8169-71ABC4D5A87B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HdrHistogram.UnitTests</RootNamespace>
<AssemblyName>HdrHistogram.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject>
</StartupObject>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<None Remove="Resources\IsLastValueBug.hgrm" />
<None Remove="Resources\jHiccup-2.0.1.logV0.hlog" />
<None Remove="Resources\jHiccup-2.0.6.logV1.hlog" />
<None Remove="Resources\jHiccup-2.0.7S.logV2.hlog" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<None Remove="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<None Remove="Resources\tagged-Log.logV2.hlog" />
<None Remove="Resources\ycsb.logV1.hlog" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConcurrentHistogramTestBase.cs" />
<Compile Include="HistogramEncodingTestBase.cs" />
<Compile Include="HistogramFactoryTests.cs" />
<Compile Include="IntConcurrentHistogramTests.cs" />
<Compile Include="IntHistogramEncodingTests.cs" />
<Compile Include="LongConcurrentHistogramTests.cs" />
<Compile Include="HistogramAssert.cs" />
<Compile Include="LongHistogramEncodingTests.cs" />
<Compile Include="HistogramIterationValueComparer.cs" />
<Compile Include="Persistence\LongConcurrentHistogramLogReaderWriterTests.cs" />
<Compile Include="Persistence\HistogramLogExtensions.cs" />
<Compile Include="Persistence\HistogramLogReaderWriterTestBase.cs" />
<Compile Include="Persistence\IntConcurrentHistogramLogReaderWriterTests.cs" />
<Compile Include="Persistence\IntHistogramLogReaderWriterTests.cs" />
<Compile Include="HistogramTestBase.cs" />
<Compile Include="IntHistogramTests.cs" />
<Compile Include="LongHistogramTests.cs" />
<Compile Include="HgrmPercentileDistrubutionOutputTests.cs" />
<Compile Include="MathEx.cs" />
<Compile Include="Persistence\LongHistogramLogReaderWriterTests.cs" />
<Compile Include="Persistence\ShortHistogramLogReaderWriterTests.cs" />
<Compile Include="Persistence\TestCaseGenerator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Recording\RecorderTestsBase.cs" />
<Compile Include="Recording\RecorderTestWithIntConcurrentHistogram.cs" />
<Compile Include="Recording\RecorderTestWithIntHistogram.cs" />
<Compile Include="Recording\RecorderTestWithLongConcurrentHistogram.cs" />
<Compile Include="Recording\RecorderTestWithLongHistogram.cs" />
<Compile Include="Recording\RecorderTestWithShortHistogram.cs" />
<Compile Include="ShortHistogramEncodingTests.cs" />
<Compile Include="ShortHistogramTests.cs" />
<Compile Include="TimeStampTests.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\IsLastValueBug.hgrm" />
<EmbeddedResource Include="Resources\jHiccup-2.0.1.logV0.hlog" />
<EmbeddedResource Include="Resources\jHiccup-2.0.6.logV1.hlog" />
<EmbeddedResource Include="Resources\jHiccup-2.0.7S.logV2.hlog" />
<EmbeddedResource Include="Resources\ycsb.logV1.hlog" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_1sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_2sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_3sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_4sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_10percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_20percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.csv" />
<EmbeddedResource Include="Resources\Sample_10kBy1k_5sf_TicksPerHour_asMs_5percPerHalfDistance.hgrm" />
<EmbeddedResource Include="Resources\tagged-Log.logV2.hlog" />
<EmbeddedResource Include="Resources\IsLastValueBug.hgrm" />
<EmbeddedResource Include="Resources\ycsb.logV1.hlog" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">
<Project>{655d9c4c-5bbd-4494-9828-ae427a1ddd01}</Project>
<Name>HdrHistogram</Name>
</ProjectReference>
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Xunit.Combinatorial" Version="1.2.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,21 +1,22 @@
using System.Globalization;
using System.IO;
using NUnit.Framework;
using System.Reflection;
using Xunit;
namespace HdrHistogram.UnitTests
{
/// <summary>
/// Validates against files generated by the official Java implementation.
/// </summary>
[TestFixture]
public sealed class HgrmPercentileDistrubutionOutputTests
{
[Test, Combinatorial]
[Theory, CombinatorialData]
public void PercentileDistrubution_hgrm_output_is_in_correct_format(
[Values(36000000000)]long highestTrackableValue,
[Values(1, 2, 3, 4, 5)]int signigicantDigits,
[Values(10000.0)]double scaling,
[Values(5, 10, 20)]int percentileTicksPerHalfDistance)
[CombinatorialValues(36000000000)]long highestTrackableValue,
[CombinatorialValues(1, 2, 3, 4, 5)]int signigicantDigits,
[CombinatorialValues(10000.0)]double scaling,
[CombinatorialValues(5, 10, 20)]int percentileTicksPerHalfDistance)
{
var fileName = $"Sample_10kBy1k_{signigicantDigits}sf_TicksPerHour_asMs_{percentileTicksPerHalfDistance}percPerHalfDistance.hgrm";
var expected = GetEmbeddedFileText(fileName);
@ -27,15 +28,15 @@ namespace HdrHistogram.UnitTests
histogram.OutputPercentileDistribution(writer, percentileTicksPerHalfDistance, scaling);
var actual = writer.ToString();
Assert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
[Test, Combinatorial]
[Theory, CombinatorialData]
public void PercentileDistrubution_csv_output_is_in_correct_format(
[Values(36000000000)]long highestTrackableValue,
[Values(1, 2, 3, 4, 5)]int signigicantDigits,
[Values(10000.0)]double scaling,
[Values(5, 10, 20)]int percentileTicksPerHalfDistance)
[CombinatorialValues(36000000000)]long highestTrackableValue,
[CombinatorialValues(1, 2, 3, 4, 5)]int signigicantDigits,
[CombinatorialValues(10000.0)]double scaling,
[CombinatorialValues(5, 10, 20)]int percentileTicksPerHalfDistance)
{
var fileName = $"Sample_10kBy1k_{signigicantDigits}sf_TicksPerHour_asMs_{percentileTicksPerHalfDistance}percPerHalfDistance.csv";
var expected = GetEmbeddedFileText(fileName);
@ -47,10 +48,10 @@ namespace HdrHistogram.UnitTests
histogram.OutputPercentileDistribution(writer, percentileTicksPerHalfDistance, scaling, true);
var actual = writer.ToString();
Assert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
[Test] //BUG https://github.com/HdrHistogram/HdrHistogram.NET/issues/39
[Fact] //BUG https://github.com/HdrHistogram/HdrHistogram.NET/issues/39
public void OnlySingleValueFlaggedAsLastValue()
{
var expected = GetEmbeddedFileText("IsLastValueBug.hgrm");
@ -76,13 +77,13 @@ namespace HdrHistogram.UnitTests
histogram.OutputPercentileDistribution(writer);
var actual = writer.ToString();
Assert.AreEqual(expected, actual);
Assert.Equal(expected, actual);
}
private Stream GetEmbeddedFileStream(string filename)
{
var fileName = string.Format(CultureInfo.InvariantCulture, "HdrHistogram.UnitTests.Resources.{0}", filename);
return GetType()
return GetType().GetTypeInfo()
.Assembly
.GetManifestResourceStream(fileName);
}

Просмотреть файл

@ -1,5 +1,8 @@
using System.Linq;
using NUnit.Framework;
using System;
using System.Linq;
using FluentAssertions;
using HdrHistogram.Iteration;
using Xunit;
namespace HdrHistogram.UnitTests
{
@ -7,22 +10,46 @@ namespace HdrHistogram.UnitTests
{
public static void AreEqual(HistogramBase expected, HistogramBase actual)
{
Assert.AreEqual(expected.GetType(), actual.GetType());
Assert.Equal(expected.GetType(), actual.GetType());
AreValueEqual(expected, actual);
}
public static void AreValueEqual(HistogramBase expected, HistogramBase actual)
{
Assert.AreEqual(expected.TotalCount, actual.TotalCount, "TotalCount property is not equal.");
Assert.AreEqual(expected.Tag, actual.Tag, "Tag property is not equal.");
Assert.AreEqual(expected.StartTimeStamp, actual.StartTimeStamp, "StartTimeStamp property is not equal.");
Assert.AreEqual(expected.EndTimeStamp, actual.EndTimeStamp, "EndTimeStamp property is not equal.");
Assert.AreEqual(expected.LowestTrackableValue, actual.LowestTrackableValue, "LowestTrackableValue property is not equal.");
Assert.AreEqual(expected.HighestTrackableValue, actual.HighestTrackableValue, "HighestTrackableValue property is not equal.");
Assert.AreEqual(expected.NumberOfSignificantValueDigits, actual.NumberOfSignificantValueDigits, "NumberOfSignificantValueDigits property is not equal.");
expected.TotalCount.Should().Be(actual.TotalCount, "TotalCount property is not equal.");
expected.Tag.Should().Be(actual.Tag, "Tag property is not equal.");
expected.StartTimeStamp.Should().Be(actual.StartTimeStamp, "StartTimeStamp property is not equal.");
expected.EndTimeStamp.Should().Be(actual.EndTimeStamp, "EndTimeStamp property is not equal.");
expected.LowestTrackableValue.Should().Be(actual.LowestTrackableValue, "LowestTrackableValue property is not equal.");
expected.HighestTrackableValue.Should().Be(actual.HighestTrackableValue, "HighestTrackableValue property is not equal.");
expected.NumberOfSignificantValueDigits.Should().Be(actual.NumberOfSignificantValueDigits, "NumberOfSignificantValueDigits property is not equal.");
var expectedValues = expected.AllValues().ToArray();
var actualValues = actual.AllValues().ToArray();
CollectionAssert.AreEqual(expectedValues, actualValues, HistogramIterationValueComparer.Instance, "Recorded values differ");
CollectionEquals(expectedValues, actualValues);
}
private static void CollectionEquals(HistogramIterationValue[] expected, HistogramIterationValue[] actual)
{
if (expected == null && actual == null)
return;
if(expected == null)
throw new Exception("Expected null array");
if (actual == null)
throw new Exception("Unexpected null array");
if(expected.Length != actual.Length)
throw new Exception($"Expected length of {expected.Length}, but recieved {actual.Length}");
for (int i = 0; i < expected.Length; i++)
{
var e = expected[i];
var a = actual[i];
if (HistogramIterationValueComparer.Instance.Compare(e, a) != 0)
{
throw new Exception($"Values differ at index {i}. Expected {e}, but recieved {a}");
}
}
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
using HdrHistogram.Encoding;
using HdrHistogram.Utilities;
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
@ -12,7 +12,7 @@ namespace HdrHistogram.UnitTests
private static readonly HistogramEncoderV2 EncoderV2 = new Encoding.HistogramEncoderV2();
[Test]
[Fact]
public void Given_a_populated_Histogram_When_encoded_and_decoded_Then_data_is_preserved()
{
var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -21,7 +21,7 @@ namespace HdrHistogram.UnitTests
HistogramAssert.AreValueEqual(source, result);
}
[Test]
[Fact]
public void Given_a_populated_Histogram_When_encoded_and_decoded_with_compression_Then_data_is_preserved()
{
var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -30,7 +30,7 @@ namespace HdrHistogram.UnitTests
HistogramAssert.AreValueEqual(source, result);
}
[Test]
[Fact]
public void Given_a_Histogram_populated_with_full_range_of_values_When_encoded_and_decoded_Then_data_is_preserved()
{
var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -39,7 +39,7 @@ namespace HdrHistogram.UnitTests
HistogramAssert.AreValueEqual(source, result);
}
[Test]
[Fact]
public void Given_a_Histogram_populated_with_full_range_of_values_When_encoded_and_decoded_with_compression_Then_data_is_preserved()
{
var source = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);

Просмотреть файл

@ -1,222 +1,232 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
public class HistogramFactoryTests
{
#region 16bit recording factory tests
[Fact]
public void CanCreateShortHistogram()
{
var actual = HistogramFactory.With16BitBucketSize()
.Create();
Assert.IsAssignableFrom<ShortHistogram>(actual);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateShortHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With16BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsAssignableFrom<ShortHistogram>(actual);
Assert.Equal(min, actual.LowestTrackableValue);
Assert.Equal(max, actual.HighestTrackableValue);
Assert.Equal(sf, actual.NumberOfSignificantValueDigits);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateShortHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With16BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsAssignableFrom<ShortHistogram>(histogram);
Assert.Equal(min, histogram.LowestTrackableValue);
Assert.Equal(max, histogram.HighestTrackableValue);
Assert.Equal(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
#region 32bit recording factory tests
[Fact]
public void CanCreateIntHistogram()
{
var actual = HistogramFactory.With32BitBucketSize()
.Create();
Assert.IsAssignableFrom<IntHistogram>(actual);
}
[Fact]
public void CanCreateIntConcurrentHistogram()
{
var actual = HistogramFactory.With32BitBucketSize()
.WithThreadSafeWrites()
.Create();
Assert.IsAssignableFrom<IntConcurrentHistogram>(actual);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class HistogramFactoryTests
{
#region 16bit recording factory tests
public void CanCreateIntHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsAssignableFrom<IntHistogram>(actual);
Assert.Equal(min, actual.LowestTrackableValue);
Assert.Equal(max, actual.HighestTrackableValue);
Assert.Equal(sf, actual.NumberOfSignificantValueDigits);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void IntConcurrentHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
[Test]
public void CanCreateShortHistogram()
{
var actual = HistogramFactory.With16BitBucketSize()
.Create();
Assert.IsInstanceOf<ShortHistogram>(actual);
}
.Create();
Assert.IsAssignableFrom<IntConcurrentHistogram>(actual);
Assert.Equal(min, actual.LowestTrackableValue);
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateShortHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With16BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsInstanceOf<ShortHistogram>(actual);
Assert.AreEqual(min, actual.LowestTrackableValue);
Assert.AreEqual(max, actual.HighestTrackableValue);
Assert.AreEqual(sf, actual.NumberOfSignificantValueDigits);
}
Assert.Equal(max, actual.HighestTrackableValue);
Assert.Equal(sf, actual.NumberOfSignificantValueDigits);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateIntHistogramRecorder(long min, long max, int sf)
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateShortHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With16BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsInstanceOf<ShortHistogram>(histogram);
Assert.AreEqual(min, histogram.LowestTrackableValue);
Assert.AreEqual(max, histogram.HighestTrackableValue);
Assert.AreEqual(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
#region 32bit recording factory tests
[Test]
public void CanCreateIntHistogram()
{
var actual = HistogramFactory.With32BitBucketSize()
.Create();
Assert.IsInstanceOf<IntHistogram>(actual);
}
[Test]
public void CanCreateIntConcurrentHistogram()
{
var actual = HistogramFactory.With32BitBucketSize()
.WithThreadSafeWrites()
.Create();
Assert.IsInstanceOf<IntConcurrentHistogram>(actual);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateIntHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsInstanceOf<IntHistogram>(actual);
Assert.AreEqual(min, actual.LowestTrackableValue);
Assert.AreEqual(max, actual.HighestTrackableValue);
Assert.AreEqual(sf, actual.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void IntConcurrentHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.Create();
Assert.IsInstanceOf<IntConcurrentHistogram>(actual);
Assert.AreEqual(min, actual.LowestTrackableValue);
Assert.AreEqual(max, actual.HighestTrackableValue);
Assert.AreEqual(sf, actual.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateIntHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsInstanceOf<IntHistogram>(histogram);
Assert.AreEqual(min, histogram.LowestTrackableValue);
Assert.AreEqual(max, histogram.HighestTrackableValue);
Assert.AreEqual(sf, histogram.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateIntConcurrentHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsInstanceOf<IntConcurrentHistogram>(histogram);
Assert.AreEqual(min, histogram.LowestTrackableValue);
Assert.AreEqual(max, histogram.HighestTrackableValue);
Assert.AreEqual(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
#region 64bit recording factory tests
[Test]
public void CanCreateLongHistogram()
{
var actual = HistogramFactory.With64BitBucketSize()
.Create();
Assert.IsInstanceOf<LongHistogram>(actual);
}
[Test]
public void CanCreateLongConcurrentHistogram()
{
var actual = HistogramFactory.With64BitBucketSize()
.WithThreadSafeWrites()
.Create();
Assert.IsInstanceOf<LongConcurrentHistogram>(actual);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateLongHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsInstanceOf<LongHistogram>(actual);
Assert.AreEqual(min, actual.LowestTrackableValue);
Assert.AreEqual(max, actual.HighestTrackableValue);
Assert.AreEqual(sf, actual.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void LongConcurrentHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.Create();
Assert.IsInstanceOf<LongConcurrentHistogram>(actual);
Assert.AreEqual(min, actual.LowestTrackableValue);
Assert.AreEqual(max, actual.HighestTrackableValue);
Assert.AreEqual(sf, actual.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateLongHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsInstanceOf<LongHistogram>(histogram);
Assert.AreEqual(min, histogram.LowestTrackableValue);
Assert.AreEqual(max, histogram.HighestTrackableValue);
Assert.AreEqual(sf, histogram.NumberOfSignificantValueDigits);
}
[TestCase(1, 5000, 3)]
[TestCase(1000, 100000, 5)]
public void CanCreateLongConcurrentHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsInstanceOf<LongConcurrentHistogram>(histogram);
Assert.AreEqual(min, histogram.LowestTrackableValue);
Assert.AreEqual(max, histogram.HighestTrackableValue);
Assert.AreEqual(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
}
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsAssignableFrom<IntHistogram>(histogram);
Assert.Equal(min, histogram.LowestTrackableValue);
Assert.Equal(max, histogram.HighestTrackableValue);
Assert.Equal(sf, histogram.NumberOfSignificantValueDigits);
}
[Theory]
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateIntConcurrentHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With32BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsAssignableFrom<IntConcurrentHistogram>(histogram);
Assert.Equal(min, histogram.LowestTrackableValue);
Assert.Equal(max, histogram.HighestTrackableValue);
Assert.Equal(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
#region 64bit recording factory tests
[Fact]
public void CanCreateLongHistogram()
{
var actual = HistogramFactory.With64BitBucketSize()
.Create();
Assert.IsAssignableFrom<LongHistogram>(actual);
}
[Fact]
public void CanCreateLongConcurrentHistogram()
{
var actual = HistogramFactory.With64BitBucketSize()
.WithThreadSafeWrites()
.Create();
Assert.IsAssignableFrom<LongConcurrentHistogram>(actual);
}
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateLongHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.Create();
Assert.IsAssignableFrom<LongHistogram>(actual);
Assert.Equal(min, actual.LowestTrackableValue);
Assert.Equal(max, actual.HighestTrackableValue);
Assert.Equal(sf, actual.NumberOfSignificantValueDigits);
}
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void LongConcurrentHistogramWithSpecifiedRangeValues(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.Create();
Assert.IsAssignableFrom<LongConcurrentHistogram>(actual);
Assert.Equal(min, actual.LowestTrackableValue);
Assert.Equal(max, actual.HighestTrackableValue);
Assert.Equal(sf, actual.NumberOfSignificantValueDigits);
}
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateLongHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsAssignableFrom<LongHistogram>(histogram);
Assert.Equal(min, histogram.LowestTrackableValue);
Assert.Equal(max, histogram.HighestTrackableValue);
Assert.Equal(sf, histogram.NumberOfSignificantValueDigits);
}
[InlineData(1, 5000, 3)]
[InlineData(1000, 100000, 5)]
public void CanCreateLongConcurrentHistogramRecorder(long min, long max, int sf)
{
var actual = HistogramFactory.With64BitBucketSize()
.WithValuesFrom(min)
.WithValuesUpTo(max)
.WithPrecisionOf(sf)
.WithThreadSafeWrites()
.WithThreadSafeReads()
.Create();
var histogram = actual.GetIntervalHistogram();
Assert.IsAssignableFrom<LongConcurrentHistogram>(histogram);
Assert.Equal(min, histogram.LowestTrackableValue);
Assert.Equal(max, histogram.HighestTrackableValue);
Assert.Equal(sf, histogram.NumberOfSignificantValueDigits);
}
#endregion
}
}

Просмотреть файл

@ -4,7 +4,7 @@ using HdrHistogram.Iteration;
namespace HdrHistogram.UnitTests
{
public class HistogramIterationValueComparer : IComparer<HistogramIterationValue>, IComparer
public sealed class HistogramIterationValueComparer : IComparer<HistogramIterationValue>, IComparer
{
public static readonly HistogramIterationValueComparer Instance = new HistogramIterationValueComparer();
@ -36,7 +36,7 @@ namespace HdrHistogram.UnitTests
public int Compare(object x, object y)
{
return Compare((HistogramIterationValue)x,(HistogramIterationValue)y);
return Compare((HistogramIterationValue)x, (HistogramIterationValue)y);
}
}
}

Просмотреть файл

@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using FluentAssertions;
using Xunit;
namespace HdrHistogram.UnitTests
{
@ -26,41 +28,43 @@ namespace HdrHistogram.UnitTests
protected abstract HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits);
protected abstract HistogramBase Create(long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits);
[TestCase(0, 1, DefaultSignificantFigures, "lowestTrackableValue", "lowestTrackableValue must be >= 1")]
[TestCase(DefautltLowestDiscernibleValue, 1, DefaultSignificantFigures, "highestTrackableValue", "highestTrackableValue must be >= 2 * lowestTrackableValue")]
[TestCase(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, 6, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[TestCase(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, -1, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[Theory]
[InlineData(0, 1, DefaultSignificantFigures, "lowestTrackableValue", "lowestTrackableValue must be >= 1")]
[InlineData(DefautltLowestDiscernibleValue, 1, DefaultSignificantFigures, "highestTrackableValue", "highestTrackableValue must be >= 2 * lowestTrackableValue")]
[InlineData(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, 6, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[InlineData(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, -1, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
public void ConstructorShouldRejectInvalidParameters(
long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits,
string errorParamName, string errorMessage)
{
var ex = Assert.Throws<ArgumentException>(() => { Create(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits); });
Assert.AreEqual(errorParamName, ex.ParamName);
StringAssert.StartsWith(errorMessage, ex.Message);
Assert.Equal(errorParamName, ex.ParamName);
Assert.StartsWith(errorMessage, ex.Message);
}
[TestCase(2, 2)]
[TestCase(DefaultHighestTrackableValue, DefaultSignificantFigures)]
public void TestConstructionArgumentGets(long highestTrackableValue, int numberOfSignificantValueDigits)
[Theory]
[InlineData(2, 2)]
[InlineData(DefaultHighestTrackableValue, DefaultSignificantFigures)]
public void Test2ConstructionArgumentGets(long highestTrackableValue, int numberOfSignificantValueDigits)
{
var histogram = Create(highestTrackableValue, numberOfSignificantValueDigits);
Assert.AreEqual(1, histogram.LowestTrackableValue);
Assert.AreEqual(highestTrackableValue, histogram.HighestTrackableValue);
Assert.AreEqual(numberOfSignificantValueDigits, histogram.NumberOfSignificantValueDigits);
Assert.Equal(1, histogram.LowestTrackableValue);
Assert.Equal(highestTrackableValue, histogram.HighestTrackableValue);
Assert.Equal(numberOfSignificantValueDigits, histogram.NumberOfSignificantValueDigits);
}
[TestCase(1, 2, 2)]
[TestCase(10, DefaultHighestTrackableValue, DefaultSignificantFigures)]
public void TestConstructionArgumentGets(long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits)
[Theory]
[InlineData(1, 2, 2)]
[InlineData(10, DefaultHighestTrackableValue, DefaultSignificantFigures)]
public void Test3ConstructionArgumentGets(long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits)
{
var histogram = Create(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits);
Assert.AreEqual(lowestTrackableValue, histogram.LowestTrackableValue);
Assert.AreEqual(highestTrackableValue, histogram.HighestTrackableValue);
Assert.AreEqual(numberOfSignificantValueDigits, histogram.NumberOfSignificantValueDigits);
Assert.Equal(lowestTrackableValue, histogram.LowestTrackableValue);
Assert.Equal(highestTrackableValue, histogram.HighestTrackableValue);
Assert.Equal(numberOfSignificantValueDigits, histogram.NumberOfSignificantValueDigits);
}
[Test]
[Fact]
public void TestGetEstimatedFootprintInBytes2()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -74,64 +78,66 @@ namespace HdrHistogram.UnitTests
var length = (bucketCount + 1) * (subBucketSize / 2);
var expectedSize = header + (width * length);
Assert.AreEqual(expectedSize, histogram.GetEstimatedFootprintInBytes());
Assert.Equal(expectedSize, histogram.GetEstimatedFootprintInBytes());
}
[Test]
[Fact]
public void RecordValue_increments_TotalCount()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
for (int i = 1; i < 5; i++)
{
histogram.RecordValue(i);
Assert.AreEqual(i, histogram.TotalCount);
Assert.Equal(i, histogram.TotalCount);
}
}
[Test]
[Fact]
public void RecordValue_increments_CountAtValue()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
for (int i = 1; i < 5; i++)
{
histogram.RecordValue(TestValueLevel);
Assert.AreEqual(i, histogram.GetCountAtValue(TestValueLevel));
Assert.Equal(i, histogram.GetCountAtValue(TestValueLevel));
}
}
[Test]
[Fact]
public void RecordValue_Overflow_ShouldThrowException()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.Throws<IndexOutOfRangeException>(() => histogram.RecordValue(DefaultHighestTrackableValue * 3));
}
[TestCase(5)]
[TestCase(100)]
[Theory]
[InlineData(5)]
[InlineData(100)]
public void RecordValueWithCount_increments_TotalCount(long multiplier)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
for (int i = 1; i < 5; i++)
{
histogram.RecordValueWithCount(i, multiplier);
Assert.AreEqual(i * multiplier, histogram.TotalCount);
Assert.Equal(i * multiplier, histogram.TotalCount);
}
}
[TestCase(5)]
[TestCase(100)]
[Theory]
[InlineData(5)]
[InlineData(100)]
public void RecordValueWithCount_increments_CountAtValue(long multiplier)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
for (int i = 1; i < 5; i++)
{
histogram.RecordValueWithCount(TestValueLevel, multiplier);
Assert.AreEqual(i * multiplier, histogram.GetCountAtValue(TestValueLevel));
Assert.Equal(i * multiplier, histogram.GetCountAtValue(TestValueLevel));
}
}
[Test]
[Fact]
public void RecordValueWithCount_Overflow_ShouldThrowException()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -139,7 +145,7 @@ namespace HdrHistogram.UnitTests
}
[Test]
[Fact]
public void RecordValueWithExpectedInterval()
{
var intervalHistogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -149,51 +155,55 @@ namespace HdrHistogram.UnitTests
valueHistogram.RecordValue(TestValueLevel);
// The data will include corrected samples:
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.AreEqual(4L, intervalHistogram.TotalCount);
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.Equal(4L, intervalHistogram.TotalCount);
// But the raw data will not:
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.AreEqual(1L, valueHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.AreEqual(1L, valueHistogram.TotalCount);
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.Equal(1L, valueHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.Equal(1L, valueHistogram.TotalCount);
}
[Test]
public void RecordAction_increments_TotalCount()
[Fact]
public void Record_increments_TotalCount()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
histogram.Record(() => { });
Assert.AreEqual(1, histogram.TotalCount);
Assert.Equal(1, histogram.TotalCount);
}
[Test]
public void RecordAction_records_in_correct_units()
[Fact]
public void Record_records_in_correct_units()
{
var pause = TimeSpan.FromSeconds(1);
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
histogram.Record(() => Thread.Sleep(pause));
histogram.Record(() =>
{
Spin.Wait(TimeSpan.FromSeconds(1));
});
var stringWriter = new StringWriter();
histogram.OutputPercentileDistribution(stringWriter,
percentileTicksPerHalfDistance: 5,
outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds,
histogram.OutputPercentileDistribution(stringWriter,
percentileTicksPerHalfDistance: 5,
outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds,
useCsvFormat: true);
//First column of second row.
var recordedMilliseconds = GetCellValue(stringWriter.ToString(), 0, 1);
var actual = double.Parse(recordedMilliseconds);
var expected = pause.TotalMilliseconds;
var delta = expected * 0.1; //10% Variance to allow for slack in transitioning from Thread.Sleep
Assert.AreEqual(expected, actual, delta);
//10% Variance to allow for slack in transitioning from Thread.Sleep
actual.Should().BeInRange(expected * 0.9, expected * 1.1);
}
[Test]
[Fact]
public void Reset_sets_counts_to_zero()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -201,12 +211,12 @@ namespace HdrHistogram.UnitTests
histogram.Reset();
Assert.AreEqual(0L, histogram.GetCountAtValue(TestValueLevel));
Assert.AreEqual(0L, histogram.TotalCount);
Assert.Equal(0L, histogram.GetCountAtValue(TestValueLevel));
Assert.Equal(0L, histogram.TotalCount);
}
[Test]
[Fact]
public void Add_should_sum_the_counts_from_two_histograms()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -218,12 +228,12 @@ namespace HdrHistogram.UnitTests
histogram.Add(other);
Assert.AreEqual(2L, histogram.GetCountAtValue(TestValueLevel));
Assert.AreEqual(2L, histogram.GetCountAtValue(TestValueLevel * 1000));
Assert.AreEqual(4L, histogram.TotalCount);
Assert.Equal(2L, histogram.GetCountAtValue(TestValueLevel));
Assert.Equal(2L, histogram.GetCountAtValue(TestValueLevel * 1000));
Assert.Equal(4L, histogram.TotalCount);
}
[Test]
[Fact]
public void Add_should_allow_small_range_hsitograms_to_be_added()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -237,12 +247,12 @@ namespace HdrHistogram.UnitTests
// Adding the smaller histogram to the bigger one should work:
biggerOther.Add(histogram);
Assert.AreEqual(2L, biggerOther.GetCountAtValue(TestValueLevel));
Assert.AreEqual(2L, biggerOther.GetCountAtValue(TestValueLevel * 1000));
Assert.AreEqual(4L, biggerOther.TotalCount);
Assert.Equal(2L, biggerOther.GetCountAtValue(TestValueLevel));
Assert.Equal(2L, biggerOther.GetCountAtValue(TestValueLevel * 1000));
Assert.Equal(4L, biggerOther.TotalCount);
}
[Test]
[Fact]
public void Add_throws_if_other_has_a_larger_range()
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -251,63 +261,67 @@ namespace HdrHistogram.UnitTests
Assert.Throws<ArgumentOutOfRangeException>(() => { histogram.Add(biggerOther); });
}
[TestCase(1, 1)]
[TestCase(2, 2500)]
[TestCase(4, 8191)]
[TestCase(8, 8192)]
[TestCase(8, 10000)]
[Theory]
[InlineData(1, 1)]
[InlineData(2, 2500)]
[InlineData(4, 8191)]
[InlineData(8, 8192)]
[InlineData(8, 10000)]
public void SizeOfEquivalentValueRangeForValue(int expected, int value)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected, histogram.SizeOfEquivalentValueRange(value));
Assert.Equal(expected, histogram.SizeOfEquivalentValueRange(value));
//Validate the scaling too.
var scaledHistogram = Create(1024, DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected * 1024, scaledHistogram.SizeOfEquivalentValueRange(value * 1024));
Assert.Equal(expected * 1024, scaledHistogram.SizeOfEquivalentValueRange(value * 1024));
}
[TestCase(10000, 10007)]
[TestCase(10008, 10009)]
[Theory]
[InlineData(10000, 10007)]
[InlineData(10008, 10009)]
public void LowestEquivalentValue_returns_the_smallest_value_that_would_be_assigned_to_the_same_count(int expected, int value)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected, histogram.LowestEquivalentValue(value));
Assert.Equal(expected, histogram.LowestEquivalentValue(value));
//Validate the scaling too
var scaledHistogram = Create(1024, DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected * 1024, scaledHistogram.LowestEquivalentValue(value * 1024));
Assert.Equal(expected * 1024, scaledHistogram.LowestEquivalentValue(value * 1024));
}
[TestCase(8183, 8180)]
[TestCase(8191, 8191)]
[TestCase(8199, 8193)]
[TestCase(9999, 9995)]
[TestCase(10007, 10007)]
[TestCase(10015, 10008)]
[Theory]
[InlineData(8183, 8180)]
[InlineData(8191, 8191)]
[InlineData(8199, 8193)]
[InlineData(9999, 9995)]
[InlineData(10007, 10007)]
[InlineData(10015, 10008)]
public void HighestEquivalentValue_returns_the_smallest_value_that_would_be_assigned_to_the_same_count(int expected, int value)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected, histogram.HighestEquivalentValue(value));
Assert.Equal(expected, histogram.HighestEquivalentValue(value));
//Validate the scaling too
var scaledHistogram = Create(1024, DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected * 1024 + 1023, scaledHistogram.HighestEquivalentValue(value * 1024));
Assert.Equal(expected * 1024 + 1023, scaledHistogram.HighestEquivalentValue(value * 1024));
}
[TestCase(4, 4, 512)]
[TestCase(5, 5, 512)]
[TestCase(4001, 4000, 0)]
[TestCase(8002, 8000, 0)]
[TestCase(10004, 10007, 0)]
[Theory]
[InlineData(4, 4, 512)]
[InlineData(5, 5, 512)]
[InlineData(4001, 4000, 0)]
[InlineData(8002, 8000, 0)]
[InlineData(10004, 10007, 0)]
public void TestMedianEquivalentValue(int expected, int value, int scaledHeader)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected, histogram.MedianEquivalentValue(value));
Assert.Equal(expected, histogram.MedianEquivalentValue(value));
//Validate the scaling too
var scaledHistogram = Create(1024, DefaultHighestTrackableValue, DefaultSignificantFigures);
Assert.AreEqual(expected * 1024 + scaledHeader, scaledHistogram.MedianEquivalentValue(value * 1024));
Assert.Equal(expected * 1024 + scaledHeader, scaledHistogram.MedianEquivalentValue(value * 1024));
}
[Test]
[Fact]
public void When_more_items_are_recorded_than_totalCount_can_hold_Then_set_HasOverflowed_to_True()
{
var histogram = Create(DefaultHighestTrackableValue, 2);
@ -319,7 +333,7 @@ namespace HdrHistogram.UnitTests
Assert.True(histogram.HasOverflowed());
}
[Test]
[Fact]
public void Can_add_Histograms_with_larger_wordSize_when_values_are_in_range()
{
var largerHistogramFactory = WordSizeToFactory.Where(kvp => kvp.Key >= WordSize).Select(kvp => kvp.Value);
@ -329,7 +343,7 @@ namespace HdrHistogram.UnitTests
}
}
[Test]
[Fact]
public void Copy_retains_all_public_properties()
{
var source = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -337,12 +351,13 @@ namespace HdrHistogram.UnitTests
HistogramAssert.AreValueEqual(source, copy);
}
[TestCase("No spaces")]
[TestCase("No,commas")]
[TestCase("\r")]
[TestCase("\n")]
[TestCase(" ")]
[TestCase(" ")]
[Theory]
[InlineData("No spaces")]
[InlineData("No,commas")]
[InlineData("\r")]
[InlineData("\n")]
[InlineData(" ")]
[InlineData(" ")]
public void Setting_invalid_value_to_Tag_throws(string invalidTagValue)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class IntConcurrentHistogramTests : ConcurrentHistogramTestBase
{
protected override int WordSize => sizeof(int);

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public sealed class IntHistogramEncodingTests : HistogramEncodingTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantDigits)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class IntHistogramTests : HistogramTestBase
{
protected override int WordSize => sizeof(int);

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class LongConcurrentHistogramTests : ConcurrentHistogramTestBase
{
protected override int WordSize => sizeof(long);

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public sealed class LongHistogramEncodingTests : HistogramEncodingTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantDigits)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class LongHistogramTests : HistogramTestBase
{
protected override int WordSize => sizeof(long);

Просмотреть файл

@ -2,8 +2,9 @@ using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using HdrHistogram.Utilities;
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
@ -14,7 +15,7 @@ namespace HdrHistogram.UnitTests.Persistence
//Used as the HighestTrackableValue when reading out test files that were generated from the original Java implementation.
private const long OneHourOfNanoseconds = 3600L * 1000 * 1000 * 1000;
[Test]
[Fact]
public void CanReadEmptyLog()
{
byte[] data;
@ -31,14 +32,15 @@ namespace HdrHistogram.UnitTests.Persistence
using (var readerStream = new MemoryStream(data))
{
var reader = new HistogramLogReader(readerStream);
CollectionAssert.IsEmpty(reader.ReadHistograms().ToList());
Assert.Empty(reader.ReadHistograms().ToList());
var actualStartTime = reader.GetStartTime().SecondsSinceUnixEpoch().Round(3);
Assert.AreEqual(expectedStartTime, actualStartTime);
Assert.Equal(expectedStartTime, actualStartTime);
}
}
[TestCase(3600L * 1000 * 1000, DefaultSignificantDigits, 1000)]
[TestCase(long.MaxValue / 2, DefaultSignificantDigits, 1000)]
[Theory]
[InlineData(3600L * 1000 * 1000, DefaultSignificantDigits, 1000)]
[InlineData(long.MaxValue / 2, DefaultSignificantDigits, 1000)]
public void CanRoundTripSingleHistogram(long highestTrackableValue, int significantDigits, int multiplier)
{
var histogram = CreatePopulatedHistogram(highestTrackableValue, significantDigits, multiplier);
@ -47,7 +49,7 @@ namespace HdrHistogram.UnitTests.Persistence
var data = histogram.WriteLog();
var actualHistograms = data.ReadHistograms();
Assert.AreEqual(1, actualHistograms.Length);
Assert.Equal(1, actualHistograms.Length);
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
}
@ -61,12 +63,13 @@ namespace HdrHistogram.UnitTests.Persistence
var data = histogram.WriteLog();
var actualHistograms = data.ReadHistograms();
Assert.AreEqual(1, actualHistograms.Length);
Assert.Equal(1, actualHistograms.Length);
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
}
[TestCase("ATag")]
[TestCase("AnotherTag")]
[Theory]
[InlineData("ATag")]
[InlineData("AnotherTag")]
public void CanRoundTripSingleHistogramsWithSparseValues(string tag)
{
var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);
@ -78,12 +81,12 @@ namespace HdrHistogram.UnitTests.Persistence
var data = histogram.WriteLog();
var actualHistograms = data.ReadHistograms();
Assert.AreEqual(1, actualHistograms.Length);
Assert.AreEqual(tag, actualHistograms[0].Tag);
Assert.Equal(1, actualHistograms.Length);
Assert.Equal(tag, actualHistograms[0].Tag);
HistogramAssert.AreValueEqual(histogram, actualHistograms.Single());
}
[Test]
[Fact]
public void CanAppendHistogram()
{
var histogram1 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits);
@ -104,12 +107,13 @@ namespace HdrHistogram.UnitTests.Persistence
}
var actualHistograms = data.ReadHistograms();
Assert.AreEqual(2, actualHistograms.Length);
Assert.Equal(2, actualHistograms.Length);
HistogramAssert.AreValueEqual(histogram1, actualHistograms.First());
HistogramAssert.AreValueEqual(histogram2, actualHistograms.Skip(1).First());
}
[TestCase("tagged-Log.logV2.hlog")]
[Theory]
[InlineData("tagged-Log.logV2.hlog")]
public void CanReadV2TaggedLogs(string logPath)
{
var readerStream = GetEmbeddedFileStream(logPath);
@ -121,7 +125,7 @@ namespace HdrHistogram.UnitTests.Persistence
foreach (var histogram in reader.ReadHistograms())
{
histogramCount++;
Assert.IsInstanceOf<HistogramBase>(histogram, "Expected integer value histograms in log file");
Assert.IsAssignableFrom<HistogramBase>(histogram);// "Expected integer value histograms in log file");
totalCount += histogram.TotalCount;
if (string.IsNullOrEmpty(histogram.Tag))
@ -134,15 +138,15 @@ namespace HdrHistogram.UnitTests.Persistence
}
}
Assert.AreEqual(42, histogramCount);
Assert.AreEqual(32290, totalCount);
Assert.Equal(42, histogramCount);
Assert.Equal(32290, totalCount);
HistogramAssert.AreValueEqual(accumulatedHistogramWithNoTag, accumulatedHistogramWithTagA);
}
[TestCase("jHiccup-2.0.7S.logV2.hlog")]
[Theory]
[InlineData("jHiccup-2.0.7S.logV2.hlog")]
public void CanReadv2Logs(string logPath)
{
var readerStream = GetEmbeddedFileStream(logPath);
@ -153,22 +157,23 @@ namespace HdrHistogram.UnitTests.Persistence
foreach (var histogram in reader.ReadHistograms())
{
histogramCount++;
Assert.IsInstanceOf<HistogramBase>(histogram, "Expected integer value histograms in log file");
Assert.IsAssignableFrom<HistogramBase>(histogram);//, "Expected integer value histograms in log file");
totalCount += histogram.TotalCount;
accumulatedHistogram.Add(histogram);
}
Assert.AreEqual(62, histogramCount);
Assert.AreEqual(48761, totalCount);
Assert.AreEqual(1745879039, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.AreEqual(1796210687, accumulatedHistogram.GetMaxValue());
Assert.AreEqual(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
Assert.Equal(62, histogramCount);
Assert.Equal(48761, totalCount);
Assert.Equal(1745879039, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.Equal(1796210687, accumulatedHistogram.GetMaxValue());
Assert.Equal(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
}
[TestCase("jHiccup-2.0.1.logV0.hlog", 0, int.MaxValue, 81, 61256, 1510998015, 1569718271, 1438869961.225)]
[TestCase("jHiccup-2.0.1.logV0.hlog", 19, 25, 25, 18492, 459007, 623103, 1438869961.225)]
[TestCase("jHiccup-2.0.1.logV0.hlog", 45, 34, 34, 25439, 1209008127, 1234173951, 1438869961.225)]
[Theory]
[InlineData("jHiccup-2.0.1.logV0.hlog", 0, int.MaxValue, 81, 61256, 1510998015, 1569718271, 1438869961.225)]
[InlineData("jHiccup-2.0.1.logV0.hlog", 19, 25, 25, 18492, 459007, 623103, 1438869961.225)]
[InlineData("jHiccup-2.0.1.logV0.hlog", 45, 34, 34, 25439, 1209008127, 1234173951, 1438869961.225)]
public void CanReadv0Logs(string logPath, int skip, int take,
int expectedHistogramCount, int expectedCombinedValueCount,
int expectedCombined999, long expectedCombinedMaxLength,
@ -189,19 +194,20 @@ namespace HdrHistogram.UnitTests.Persistence
totalCount += histogram.TotalCount;
accumulatedHistogram.Add(histogram);
}
Assert.AreEqual(expectedHistogramCount, histogramCount);
Assert.AreEqual(expectedCombinedValueCount, totalCount);
Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
Assert.Equal(expectedHistogramCount, histogramCount);
Assert.Equal(expectedCombinedValueCount, totalCount);
Assert.Equal(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.Equal(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.Equal(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
}
[TestCase("jHiccup-2.0.6.logV1.hlog", 0, int.MaxValue, 88, 65964, 1829765119, 1888485375, 1438867590.285)]
[TestCase("jHiccup-2.0.6.logV1.hlog", 5, 15, 15, 11213, 1019740159, 1032323071, 1438867590.285)]
[TestCase("jHiccup-2.0.6.logV1.hlog", 50, 29, 29, 22630, 1871708159, 1888485375, 1438867590.285)]
[TestCase("ycsb.logV1.hlog", 0, int.MaxValue, 602, 300056, 1214463, 1546239, 1438613579.295)]
[TestCase("ycsb.logV1.hlog", 0, 180, 180, 89893, 1375231, 1546239, 1438613579.295)]
[TestCase("ycsb.logV1.hlog", 180, 520, 422, 210163, 530, 17775, 1438613579.295)]
[Theory]
[InlineData("jHiccup-2.0.6.logV1.hlog", 0, int.MaxValue, 88, 65964, 1829765119, 1888485375, 1438867590.285)]
[InlineData("jHiccup-2.0.6.logV1.hlog", 5, 15, 15, 11213, 1019740159, 1032323071, 1438867590.285)]
[InlineData("jHiccup-2.0.6.logV1.hlog", 50, 29, 29, 22630, 1871708159, 1888485375, 1438867590.285)]
[InlineData("ycsb.logV1.hlog", 0, int.MaxValue, 602, 300056, 1214463, 1546239, 1438613579.295)]
[InlineData("ycsb.logV1.hlog", 0, 180, 180, 89893, 1375231, 1546239, 1438613579.295)]
[InlineData("ycsb.logV1.hlog", 180, 520, 422, 210163, 530, 17775, 1438613579.295)]
public void CanReadv1Logs(string logPath, int skip, int take,
int expectedHistogramCount, int expectedCombinedValueCount,
int expectedCombined999, long expectedCombinedMaxLength,
@ -223,15 +229,16 @@ namespace HdrHistogram.UnitTests.Persistence
accumulatedHistogram.Add(histogram);
}
Assert.AreEqual(expectedHistogramCount, histogramCount);
Assert.AreEqual(expectedCombinedValueCount, totalCount);
Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
Assert.Equal(expectedHistogramCount, histogramCount);
Assert.Equal(expectedCombinedValueCount, totalCount);
Assert.Equal(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.Equal(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.Equal(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
}
[TestCase("ycsb.logV1.hlog", 0, 180, 180, 90033, 1375231, 1546239, 1438613579.295)]
[TestCase("ycsb.logV1.hlog", 180, 520, 421, 209686, 530, 17775, 1438613579.295)]
[Theory]
[InlineData("ycsb.logV1.hlog", 0, 180, 180, 90033, 1375231, 1546239, 1438613579.295)]
[InlineData("ycsb.logV1.hlog", 180, 520, 421, 209686, 530, 17775, 1438613579.295)]
public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take,
int expectedHistogramCount, int expectedCombinedValueCount,
int expectedCombined999, long expectedCombinedMaxLength,
@ -254,11 +261,11 @@ namespace HdrHistogram.UnitTests.Persistence
accumulatedHistogram.Add(histogram);
}
Assert.AreEqual(expectedHistogramCount, histogramCount);
Assert.AreEqual(expectedCombinedValueCount, totalCount);
Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
Assert.Equal(expectedHistogramCount, histogramCount);
Assert.Equal(expectedCombinedValueCount, totalCount);
Assert.Equal(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
Assert.Equal(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
Assert.Equal(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
}
private HistogramBase CreatePopulatedHistogram(long highestTrackableValue, int significantDigits, int multiplier)
@ -282,7 +289,7 @@ namespace HdrHistogram.UnitTests.Persistence
private Stream GetEmbeddedFileStream(string filename)
{
var fileName = string.Format(CultureInfo.InvariantCulture, "HdrHistogram.UnitTests.Resources.{0}", filename);
return GetType()
return GetType().GetTypeInfo()
.Assembly
.GetManifestResourceStream(fileName);
}

Просмотреть файл

@ -1,8 +1,9 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
[TestFixture]
public sealed class IntConcurrentHistogramLogReaderWriterTests : HistogramLogReaderWriterTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits)
@ -10,10 +11,17 @@ namespace HdrHistogram.UnitTests.Persistence
return new IntConcurrentHistogram(1, highestTrackableValue, numberOfSignificantValueDigits);
}
[Test, TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.PowersOfTwo), new object[] { 31 })]
[Theory]
[MemberData(nameof(PowersOfTwo))]
public void CanRoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
{
RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(count);
}
public static IEnumerable<object[]> PowersOfTwo()
{
return TestCaseGenerator.PowersOfTwo(31)
.Select(v=>new object[1]{v});
}
}
}

Просмотреть файл

@ -1,19 +1,27 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
[TestFixture]
public sealed class IntHistogramLogReaderWriterTests : HistogramLogReaderWriterTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits)
{
return new IntHistogram(highestTrackableValue, numberOfSignificantValueDigits);
}
[Test, TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.PowersOfTwo), new object[] { 31 })]
[Theory]
[MemberData(nameof(PowersOfTwo))]
public void CanRoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
{
RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(count);
}
public static IEnumerable<object[]> PowersOfTwo()
{
return TestCaseGenerator.PowersOfTwo(31)
.Select(v => new object[1] { v });
}
}
}

Просмотреть файл

@ -1,8 +1,10 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
[TestFixture]
public sealed class LongConcurrentHistogramLogReaderWriterTests : HistogramLogReaderWriterTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits)
@ -10,10 +12,17 @@ namespace HdrHistogram.UnitTests.Persistence
return new LongConcurrentHistogram(1, highestTrackableValue, numberOfSignificantValueDigits);
}
[Test, TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.PowersOfTwo), new object[] { 63 })]
[Theory]
[MemberData(nameof(PowersOfTwo))]
public void CanRoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
{
RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(count);
}
public static IEnumerable<object[]> PowersOfTwo()
{
return TestCaseGenerator.PowersOfTwo(63)
.Select(v => new object[1] { v });
}
}
}

Просмотреть файл

@ -1,19 +1,29 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
[TestFixture]
public sealed class LongHistogramLogReaderWriterTests : HistogramLogReaderWriterTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits)
{
return new LongHistogram(highestTrackableValue, numberOfSignificantValueDigits);
}
[Test, TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.PowersOfTwo), new object[] { 63 })]
[Theory]
[MemberData(nameof(PowersOfTwo))]
public void CanRoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
{
RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(count);
}
public static IEnumerable<object[]> PowersOfTwo()
{
return TestCaseGenerator.PowersOfTwo(63)
.Select(v => new object[1] { v });
}
}
}

Просмотреть файл

@ -1,8 +1,10 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace HdrHistogram.UnitTests.Persistence
{
[TestFixture]
public sealed class ShortHistogramLogReaderWriterTests : HistogramLogReaderWriterTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantValueDigits)
@ -10,10 +12,17 @@ namespace HdrHistogram.UnitTests.Persistence
return new ShortHistogram(highestTrackableValue, numberOfSignificantValueDigits);
}
[Test, TestCaseSource(typeof(TestCaseGenerator), nameof(TestCaseGenerator.PowersOfTwo), new object[] { 15 })]
[Theory]
[MemberData(nameof(PowersOfTwo))]
public void CanRoundTripSingleHistogramsWithFullRangesOfCountsAndValues(long count)
{
RoundTripSingleHistogramsWithFullRangesOfCountsAndValues(count);
}
public static IEnumerable<object[]> PowersOfTwo()
{
return TestCaseGenerator.PowersOfTwo(15)
.Select(v => new object[1] { v });
}
}
}

Просмотреть файл

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HdrHistogram.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HdrHistogram.Test")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ed97127a-d4a3-469c-a4e0-b482bc01a323")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
[TestFixture]
public sealed class RecorderTestWithIntConcurrentHistogram : RecorderTestsBase
{
protected override HistogramBase CreateHistogram(long id, long min, long max, int sf)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
[TestFixture]
public sealed class RecorderTestWithIntHistogram : RecorderTestsBase
{
protected override HistogramBase CreateHistogram(long id, long min, long max, int sf)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
[TestFixture]
public sealed class RecorderTestWithLongConcurrentHistogram : RecorderTestsBase
{
protected override HistogramBase CreateHistogram(long id, long min, long max, int sf)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
[TestFixture]
public sealed class RecorderTestWithLongHistogram : RecorderTestsBase
{
protected override HistogramBase CreateHistogram(long id, long min, long max, int sf)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
[TestFixture]
public sealed class RecorderTestWithShortHistogram : RecorderTestsBase
{
protected override HistogramBase CreateHistogram(long id, long min, long max, int sf)

Просмотреть файл

@ -1,6 +1,6 @@
using System;
using HdrHistogram.Utilities;
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests.Recording
{
@ -13,10 +13,11 @@ namespace HdrHistogram.UnitTests.Recording
protected abstract HistogramBase CreateHistogram(long id, long min, long max, int sf);
protected abstract Recorder Create(long min, long max, int sf);
[TestCase(0, 1, DefaultSignificantFigures, "lowestTrackableValue", "lowestTrackableValue must be >= 1")]
[TestCase(1, 1, DefaultSignificantFigures, "highestTrackableValue", "highestTrackableValue must be >= 2 * lowestTrackableValue")]
[TestCase(1, DefaultHighestTrackableValue, 6, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[TestCase(1, DefaultHighestTrackableValue, -1, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[Theory]
[InlineData(0, 1, DefaultSignificantFigures, "lowestTrackableValue", "lowestTrackableValue must be >= 1")]
[InlineData(1, 1, DefaultSignificantFigures, "highestTrackableValue", "highestTrackableValue must be >= 2 * lowestTrackableValue")]
[InlineData(1, DefaultHighestTrackableValue, 6, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
[InlineData(1, DefaultHighestTrackableValue, -1, "numberOfSignificantValueDigits", "numberOfSignificantValueDigits must be between 0 and 5")]
public void ConstructorShouldRejectInvalidParameters(
long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits,
string errorParamName, string errorMessage)
@ -25,11 +26,11 @@ namespace HdrHistogram.UnitTests.Recording
Create(lowestTrackableValue,
highestTrackableValue,
numberOfSignificantValueDigits));
Assert.AreEqual(errorParamName, ex.ParamName);
StringAssert.StartsWith(errorMessage, ex.Message);
Assert.Equal(errorParamName, ex.ParamName);
Assert.StartsWith(errorMessage, ex.Message);
}
[Test]
[Fact]
public void GetIntervalHistogram_returns_alternating_instances_from_factory()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -38,13 +39,13 @@ namespace HdrHistogram.UnitTests.Recording
var c = recorder.GetIntervalHistogram(b);
var d = recorder.GetIntervalHistogram(c);
Assert.AreNotSame(a, b);
Assert.AreSame(a, c);
Assert.AreNotSame(a, d);
Assert.AreSame(b, d);
Assert.NotSame(a, b);
Assert.Same(a, c);
Assert.NotSame(a, d);
Assert.Same(b, d);
}
[Test]
[Fact]
public void GetIntervalHistogram_returns_current_histogram_values()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -52,29 +53,29 @@ namespace HdrHistogram.UnitTests.Recording
recorder.RecordValue(10);
recorder.RecordValue(100);
var histogram = recorder.GetIntervalHistogram();
Assert.AreEqual(1, histogram.GetCountAtValue(1));
Assert.AreEqual(1, histogram.GetCountAtValue(10));
Assert.AreEqual(1, histogram.GetCountAtValue(100));
Assert.Equal(1, histogram.GetCountAtValue(1));
Assert.Equal(1, histogram.GetCountAtValue(10));
Assert.Equal(1, histogram.GetCountAtValue(100));
}
[Test]
[Fact]
public void GetIntervalHistogram_causes_recording_to_happen_on_new_histogram()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
recorder.RecordValue(1);
var histogramPrimary = recorder.GetIntervalHistogram();
Assert.AreEqual(1, histogramPrimary.GetCountAtValue(1));
Assert.Equal(1, histogramPrimary.GetCountAtValue(1));
recorder.RecordValue(10);
recorder.RecordValue(100);
var histogramSecondary = recorder.GetIntervalHistogram(histogramPrimary);
Assert.AreEqual(0, histogramSecondary.GetCountAtValue(1));
Assert.AreEqual(1, histogramSecondary.GetCountAtValue(10));
Assert.AreEqual(1, histogramSecondary.GetCountAtValue(100));
Assert.Equal(0, histogramSecondary.GetCountAtValue(1));
Assert.Equal(1, histogramSecondary.GetCountAtValue(10));
Assert.Equal(1, histogramSecondary.GetCountAtValue(100));
}
[Test]
[Fact]
public void GetIntervalHistogram_resets_recycled_histogram()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -88,24 +89,24 @@ namespace HdrHistogram.UnitTests.Recording
recorder.RecordValue(100);
var histogramSecondary = recorder.GetIntervalHistogram(histogramPrimary);
Assert.AreEqual(0, histogramPrimary.GetCountAtValue(1));
Assert.AreEqual(0, histogramPrimary.GetCountAtValue(10));
Assert.AreEqual(0, histogramPrimary.GetCountAtValue(100));
Assert.AreEqual(1, histogramSecondary.GetCountAtValue(1));
Assert.AreEqual(1, histogramSecondary.GetCountAtValue(10));
Assert.AreEqual(1, histogramSecondary.GetCountAtValue(100));
Assert.Equal(0, histogramPrimary.GetCountAtValue(1));
Assert.Equal(0, histogramPrimary.GetCountAtValue(10));
Assert.Equal(0, histogramPrimary.GetCountAtValue(100));
Assert.Equal(1, histogramSecondary.GetCountAtValue(1));
Assert.Equal(1, histogramSecondary.GetCountAtValue(10));
Assert.Equal(1, histogramSecondary.GetCountAtValue(100));
}
[Test]
[Fact]
public void RecordValue_increments_TotalCount()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
recorder.RecordValue(1000);
var histogram = recorder.GetIntervalHistogram();
Assert.AreEqual(1, histogram.TotalCount);
Assert.Equal(1, histogram.TotalCount);
}
[Test]
[Fact]
public void RecordValue_increments_CountAtValue()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -113,10 +114,10 @@ namespace HdrHistogram.UnitTests.Recording
recorder.RecordValue(1000);
recorder.RecordValue(1000);
var histogram = recorder.GetIntervalHistogram();
Assert.AreEqual(3, histogram.GetCountAtValue(1000));
Assert.Equal(3, histogram.GetCountAtValue(1000));
}
[Test]
[Fact]
public void RecordValue_Overflow_ShouldThrowException()
{
var highestTrackableValue = DefaultHighestTrackableValue;
@ -124,16 +125,16 @@ namespace HdrHistogram.UnitTests.Recording
Assert.Throws<IndexOutOfRangeException>(() => recorder.RecordValue(highestTrackableValue * 3));
}
[Test]
[Fact]
public void RecordValueWithCount_increments_TotalCount()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
recorder.RecordValueWithCount(1000, 10);
var histogram = recorder.GetIntervalHistogram();
Assert.AreEqual(10, histogram.TotalCount);
Assert.Equal(10, histogram.TotalCount);
}
[Test]
[Fact]
public void RecordValueWithCount_increments_CountAtValue()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -141,11 +142,11 @@ namespace HdrHistogram.UnitTests.Recording
recorder.RecordValueWithCount(1000, 10);
recorder.RecordValueWithCount(5000, 20);
var histogram = recorder.GetIntervalHistogram();
Assert.AreEqual(20, histogram.GetCountAtValue(1000));
Assert.AreEqual(20, histogram.GetCountAtValue(5000));
Assert.Equal(20, histogram.GetCountAtValue(1000));
Assert.Equal(20, histogram.GetCountAtValue(5000));
}
[Test]
[Fact]
public void RecordValueWithCount_Overflow_ShouldThrowException()
{
var highestTrackableValue = DefaultHighestTrackableValue;
@ -153,7 +154,7 @@ namespace HdrHistogram.UnitTests.Recording
Assert.Throws<IndexOutOfRangeException>(() => recorder.RecordValueWithCount(highestTrackableValue * 3, 100));
}
[Test]
[Fact]
public void RecordValueWithExpectedInterval()
{
var TestValueLevel = 4L;
@ -165,20 +166,20 @@ namespace HdrHistogram.UnitTests.Recording
var intervalHistogram = recorder.GetIntervalHistogram();
// The data will include corrected samples:
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.AreEqual(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.AreEqual(4L, intervalHistogram.TotalCount);
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.Equal(1L, intervalHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.Equal(4L, intervalHistogram.TotalCount);
// But the raw data will not:
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.AreEqual(0L, valueHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.AreEqual(1L, valueHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.AreEqual(1L, valueHistogram.TotalCount);
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
Assert.Equal(0L, valueHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
Assert.Equal(1L, valueHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
Assert.Equal(1L, valueHistogram.TotalCount);
}
[Test]
[Fact]
public void RecordAction_increments_TotalCount()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -186,10 +187,10 @@ namespace HdrHistogram.UnitTests.Recording
recorder.Record(() => { });
var longHistogram = recorder.GetIntervalHistogram();
Assert.AreEqual(1, longHistogram.TotalCount);
Assert.Equal(1, longHistogram.TotalCount);
}
[Test]
[Fact]
public void Reset_clears_counts_for_instances()
{
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
@ -206,11 +207,11 @@ namespace HdrHistogram.UnitTests.Recording
var histogramSecondary = recorder.GetIntervalHistogram(histogramPrimary);
Assert.AreEqual(0, histogramPrimary.TotalCount);
Assert.AreEqual(0, histogramSecondary.TotalCount);
Assert.Equal(0, histogramPrimary.TotalCount);
Assert.Equal(0, histogramSecondary.TotalCount);
}
[Test]
[Fact]
public void GetIntervalHistogramInto_copies_data_over_provided_Histogram()
{
var originalStart = DateTime.Today.AddDays(-1).MillisecondsSinceUnixEpoch();
@ -223,10 +224,10 @@ namespace HdrHistogram.UnitTests.Recording
targetHistogram.EndTimeStamp = originalEnd;
Assert.AreEqual(3, targetHistogram.TotalCount);
Assert.AreEqual(1, targetHistogram.GetCountAtValue(1));
Assert.AreEqual(1, targetHistogram.GetCountAtValue(10));
Assert.AreEqual(1, targetHistogram.GetCountAtValue(100));
Assert.Equal(3, targetHistogram.TotalCount);
Assert.Equal(1, targetHistogram.GetCountAtValue(1));
Assert.Equal(1, targetHistogram.GetCountAtValue(10));
Assert.Equal(1, targetHistogram.GetCountAtValue(100));
var recorder = Create(DefautltLowestDiscernibleValue, DefaultHighestTrackableValue, DefaultSignificantFigures);
recorder.RecordValue(1000);
@ -235,18 +236,18 @@ namespace HdrHistogram.UnitTests.Recording
recorder.GetIntervalHistogramInto(targetHistogram);
Assert.AreEqual(3, targetHistogram.TotalCount);
Assert.AreEqual(0, targetHistogram.GetCountAtValue(1));
Assert.AreEqual(0, targetHistogram.GetCountAtValue(10));
Assert.AreEqual(0, targetHistogram.GetCountAtValue(100));
Assert.AreEqual(1, targetHistogram.GetCountAtValue(1000));
Assert.AreEqual(1, targetHistogram.GetCountAtValue(10000));
Assert.AreEqual(1, targetHistogram.GetCountAtValue(100000));
Assert.AreNotEqual(originalStart, targetHistogram.StartTimeStamp);
Assert.AreNotEqual(originalEnd, targetHistogram.EndTimeStamp);
Assert.Equal(3, targetHistogram.TotalCount);
Assert.Equal(0, targetHistogram.GetCountAtValue(1));
Assert.Equal(0, targetHistogram.GetCountAtValue(10));
Assert.Equal(0, targetHistogram.GetCountAtValue(100));
Assert.Equal(1, targetHistogram.GetCountAtValue(1000));
Assert.Equal(1, targetHistogram.GetCountAtValue(10000));
Assert.Equal(1, targetHistogram.GetCountAtValue(100000));
Assert.NotEqual(originalStart, targetHistogram.StartTimeStamp);
Assert.NotEqual(originalEnd, targetHistogram.EndTimeStamp);
}
[Test]
[Fact]
public void Using_external_histogram_for_recycling_throws()
{
const int id = -1000;

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public sealed class ShortHistogramEncodingTests : HistogramEncodingTestBase
{
protected override HistogramBase Create(long highestTrackableValue, int numberOfSignificantDigits)

Просмотреть файл

@ -1,8 +1,8 @@
using NUnit.Framework;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class ShortHistogramTests : HistogramTestBase
{
protected override int WordSize => sizeof(short);

Просмотреть файл

@ -0,0 +1,25 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;
//It seems for the most reliable tests, running them single threaded doesn't
// saturate the OS Thread scheduler and therfore doesn't lead to extended
// pauses when executing one of our many dealy/sleep paths.
//I have tried to consolidate them all to use this one class, so if they are
// abandoned, then this DisableTestParallelization can be removed too. -LC
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace HdrHistogram.UnitTests
{
public static class Spin
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Wait(TimeSpan period)
{
var sw = Stopwatch.StartNew();
SpinWait.SpinUntil(() => period < sw.Elapsed);
}
}
}

Просмотреть файл

@ -1,27 +1,28 @@
using System;
using System.Diagnostics;
using System.Threading;
using NUnit.Framework;
using FluentAssertions;
using Xunit;
namespace HdrHistogram.UnitTests
{
[TestFixture]
public class TimeStampTests
{
[Test]
[Fact]
public void TimeStamp_values_are_accurate()
{
var delay = TimeSpan.FromSeconds(1);
var expected = TimeStamp.Seconds(delay.Seconds);
long minAccepted = (long)(expected * 0.95);
long maxAccepted = (long)(expected * 1.05);
var start = Stopwatch.GetTimestamp();
Thread.Sleep(delay);
Spin.Wait(delay);
var end = Stopwatch.GetTimestamp();
var actual = end - start;
Assert.AreEqual(expected, actual, expected * 0.05);
Assert.AreEqual(TimeStamp.Seconds(60), TimeStamp.Minutes(1));
Assert.AreEqual(TimeStamp.Minutes(60), TimeStamp.Hours(1));
}
actual.Should().BeInRange(minAccepted, maxAccepted);
Assert.Equal(TimeStamp.Seconds(60), TimeStamp.Minutes(1));
Assert.Equal(TimeStamp.Minutes(60), TimeStamp.Hours(1));
}
}
}

Просмотреть файл

@ -1,3 +0,0 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>

Просмотреть файл

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.2.0" targetFramework="net452" />
</packages>

Просмотреть файл

@ -1,30 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.26430.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram", "HdrHistogram\HdrHistogram.csproj", "{655D9C4C-5BBD-4494-9828-AE427A1DDD01}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram", "HdrHistogram\HdrHistogram.csproj", "{54D17764-192D-469B-8DCA-BCA216EDD6E5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F2800CBA-6CFC-45FE-AA8F-25E4FF912E41}"
ProjectSection(SolutionItems) = preProject
..\LICENSE.txt = ..\LICENSE.txt
..\README.md = ..\README.md
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram.Examples", "HdrHistogram.Examples\HdrHistogram.Examples.csproj", "{4C6EE683-FB7D-4A88-93D6-0FE2763B5723}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{48A302F0-0D3C-4616-B4D0-7B64CE75AB1D}"
ProjectSection(SolutionItems) = preProject
..\build\build.cmd = ..\build\build.cmd
..\build\build.ps1 = ..\build\build.ps1
..\build\HdrHistogram.nuspec = ..\build\HdrHistogram.nuspec
EndProjectSection
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HdrHistogram.UnitTests", "HdrHistogram.UnitTests\HdrHistogram.UnitTests.csproj", "{42E25BE5-BE7B-4B31-BBCE-7A38DE06890A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram.UnitTests", "HdrHistogram.UnitTests\HdrHistogram.UnitTests.csproj", "{2D189069-FE39-42AE-8169-71ABC4D5A87B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D3EBE9D9-B40D-4D2F-B76D-16A34FB09A94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram.Examples", "HdrHistogram.Examples\HdrHistogram.Examples.csproj", "{E210C748-4792-4658-9345-CC073C29EC0B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram.Benchmarking", "HdrHistogram.Benchmarking\HdrHistogram.Benchmarking.csproj", "{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HdrHistogram.Benchmarking", "HdrHistogram.Benchmarking\HdrHistogram.Benchmarking.csproj", "{3469742E-EFDD-457C-9E33-26E59D34CE63}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -32,28 +17,24 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{655D9C4C-5BBD-4494-9828-AE427A1DDD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{655D9C4C-5BBD-4494-9828-AE427A1DDD01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{655D9C4C-5BBD-4494-9828-AE427A1DDD01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{655D9C4C-5BBD-4494-9828-AE427A1DDD01}.Release|Any CPU.Build.0 = Release|Any CPU
{2D189069-FE39-42AE-8169-71ABC4D5A87B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D189069-FE39-42AE-8169-71ABC4D5A87B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D189069-FE39-42AE-8169-71ABC4D5A87B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D189069-FE39-42AE-8169-71ABC4D5A87B}.Release|Any CPU.Build.0 = Release|Any CPU
{E210C748-4792-4658-9345-CC073C29EC0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E210C748-4792-4658-9345-CC073C29EC0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E210C748-4792-4658-9345-CC073C29EC0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E210C748-4792-4658-9345-CC073C29EC0B}.Release|Any CPU.Build.0 = Release|Any CPU
{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B}.Release|Any CPU.Build.0 = Release|Any CPU
{54D17764-192D-469B-8DCA-BCA216EDD6E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54D17764-192D-469B-8DCA-BCA216EDD6E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54D17764-192D-469B-8DCA-BCA216EDD6E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54D17764-192D-469B-8DCA-BCA216EDD6E5}.Release|Any CPU.Build.0 = Release|Any CPU
{4C6EE683-FB7D-4A88-93D6-0FE2763B5723}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C6EE683-FB7D-4A88-93D6-0FE2763B5723}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C6EE683-FB7D-4A88-93D6-0FE2763B5723}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C6EE683-FB7D-4A88-93D6-0FE2763B5723}.Release|Any CPU.Build.0 = Release|Any CPU
{42E25BE5-BE7B-4B31-BBCE-7A38DE06890A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42E25BE5-BE7B-4B31-BBCE-7A38DE06890A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42E25BE5-BE7B-4B31-BBCE-7A38DE06890A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42E25BE5-BE7B-4B31-BBCE-7A38DE06890A}.Release|Any CPU.Build.0 = Release|Any CPU
{3469742E-EFDD-457C-9E33-26E59D34CE63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3469742E-EFDD-457C-9E33-26E59D34CE63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3469742E-EFDD-457C-9E33-26E59D34CE63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3469742E-EFDD-457C-9E33-26E59D34CE63}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2D189069-FE39-42AE-8169-71ABC4D5A87B} = {D3EBE9D9-B40D-4D2F-B76D-16A34FB09A94}
{8AAE86BE-5ABC-4902-B48B-20DCDBB93C7B} = {D3EBE9D9-B40D-4D2F-B76D-16A34FB09A94}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,110 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{655D9C4C-5BBD-4494-9828-AE427A1DDD01}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HdrHistogram</RootNamespace>
<AssemblyName>HdrHistogram</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFramework>netstandard1.3</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\Net45\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.3\HdrHistogram.xml</DocumentationFile>
<DefineConstants>RELEASE;NETSTANDARD1_3</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\Net45\</OutputPath>
<IntermediateOutputPath>obj\Release\Net45\</IntermediateOutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<DocumentationFile>bin\Release\Net45\HdrHistogram.XML</DocumentationFile>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Histogram.cs" />
<Compile Include="HistogramFactoryDelegate.cs" />
<Compile Include="IntConcurrentHistogram.cs" />
<Compile Include="LongConcurrentHistogram.cs" />
<Compile Include="HistogramEncoding.cs" />
<Compile Include="Encoding\HistogramEncoderV2.cs" />
<Compile Include="Encoding\IEncoder.cs" />
<Compile Include="Encoding\IHeader.cs" />
<Compile Include="Encoding\IRecordedData.cs" />
<Compile Include="Encoding\RecordedData.cs" />
<Compile Include="Encoding\V0Header.cs" />
<Compile Include="Encoding\V1Header.cs" />
<Compile Include="HistogramBase.cs" />
<Compile Include="HistogramExtensions.cs" />
<Compile Include="HistogramLogReader.cs" />
<Compile Include="HistogramLogWriter.cs" />
<Compile Include="IHistogramLogV1Reader.cs" />
<Compile Include="IntHistogram.cs" />
<Compile Include="IRecorder.cs" />
<Compile Include="Iteration\AbstractHistogramEnumerator.cs" />
<Compile Include="Iteration\AllValueEnumerable.cs" />
<Compile Include="Iteration\AllValuesEnumerator.cs" />
<Compile Include="Iteration\HistogramIterationValue.cs" />
<Compile Include="Iteration\PercentileEnumerable.cs" />
<Compile Include="Iteration\PercentileEnumerator.cs" />
<Compile Include="Iteration\RecordedValuesEnumerable.cs" />
<Compile Include="Iteration\RecordedValuesEnumerator.cs" />
<Compile Include="OutputScalingFactor.cs" />
<Compile Include="Output\CsvOutputFormatter.cs" />
<Compile Include="Output\HgrmOutputFormatter.cs" />
<Compile Include="Output\IOutputFormatter.cs" />
<Compile Include="Persistence\CountsDecoder.cs" />
<Compile Include="Persistence\ICountsDecoder.cs" />
<Compile Include="Persistence\IntCountsDecoder.cs" />
<Compile Include="Persistence\LongCountsDecoder.cs" />
<Compile Include="Persistence\ShortCountsDecoder.cs" />
<Compile Include="Persistence\SimpleCountsDecoder.cs" />
<Compile Include="Persistence\V2MaxWordSizeCountsDecoder.cs" />
<Compile Include="Properties\AssemblyInfo.g.cs" />
<Compile Include="Recorder.cs" />
<Compile Include="ShortHistogram.cs" />
<Compile Include="TimeStamp.cs" />
<Compile Include="Utilities\ArrayExtensions.cs" />
<Compile Include="Utilities\AtomicIntArray.cs" />
<Compile Include="Utilities\AtomicLongArray.cs" />
<Compile Include="Utilities\Bitwise.cs" />
<Compile Include="LongHistogram.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\ByteBuffer.cs" />
<Compile Include="Utilities\ByteBufferExtensions.cs" />
<Compile Include="Utilities\TypeHelper.cs" />
<Compile Include="Utilities\UnixTimeExtensions.cs" />
<Compile Include="Utilities\WriterReaderPhaser.cs" />
<Compile Include="ZigZagEncoding.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -253,7 +253,7 @@ namespace HdrHistogram
/// To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples,
/// Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.
/// <para>
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by <see cref="CopyCorrectedForCoordinatedOmission"/>.
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by currently unimplemented <c>CopyCorrectedForCoordinatedOmission</c> method.
/// The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.
/// </para>
/// See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

Просмотреть файл

@ -30,7 +30,7 @@
/// To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples,
/// Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.
/// <para>
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by <see cref="CopyCorrectedForCoordinatedOmission"/>.
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by currently unimplemented <c>CopyCorrectedForCoordinatedOmission</c> method.
/// The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.
/// </para>
/// See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

Просмотреть файл

@ -1,16 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled from attributes in the generated file AssemblyInfo.g.cs
[assembly: AssemblyTitle("HdrHistogram")]
[assembly: AssemblyDescription("High Dynamic Range Histogram for .NET")]
[assembly: AssemblyCopyright("Copyright © 2015. All rights reserved.")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// Versioning attributes in the generated file AssemblyInfo.g.cs

Просмотреть файл

@ -1,16 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: System.Reflection.AssemblyConfiguration("Release")]
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0-beta")]

Просмотреть файл

@ -106,7 +106,7 @@ namespace HdrHistogram
/// To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples,
/// Histogram will auto-generate an additional series of decreasingly-smaller (down to the expectedIntervalBetweenValueSamples) value records.
/// <para>
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by <see cref="CopyCorrectedForCoordinatedOmission"/>.
/// Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by currently unimplemented <c>CopyCorrectedForCoordinatedOmission</c> method.
/// The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.
/// </para>
/// See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

Просмотреть файл

@ -64,7 +64,8 @@ namespace HdrHistogram.Utilities
_counts[index] = value;
// Is this right, is that all we need??? We definitely don't want an Interlocked here, that's too much!!
Thread.MemoryBarrier();
//Thread.MemoryBarrier();
Interlocked.MemoryBarrier();
//Volatile.Read (only emits half-fence (acquire fence) as opposed to Thread.VolatileRead which emits a full-fence

Просмотреть файл

@ -73,7 +73,8 @@ namespace HdrHistogram.Utilities
_counts[index] = value;
// Is this right, is that all we need??? We definitely don't want an Interlocked here, that's too much!!
Thread.MemoryBarrier();
//Thread.MemoryBarrier();
Interlocked.MemoryBarrier();
//Volatile.Read (only emits half-fence (acquire fence) as opposed to Thread.VolatileRead which emits a full-fence

Просмотреть файл

@ -8,6 +8,7 @@
using System;
namespace HdrHistogram.Utilities
{
//Code has been tested and taken from :
@ -17,7 +18,11 @@ namespace HdrHistogram.Utilities
//http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
//
//Ideally newer versions of .NET will expose the CPU instructions to do this Intel SSE 'lzcnt' (Leading Zero Count), or give access to the BitScanReverse VC++ functions (https://msdn.microsoft.com/en-us/library/fbxyd7zd.aspx)
internal static class Bitwise
/// <summary>
/// Exposes optimised methods to get Leading Zero Count.
/// </summary>
public static class Bitwise
{
private static readonly int[] Lookup;
@ -29,6 +34,12 @@ namespace HdrHistogram.Utilities
Lookup[i] = (int)(Math.Log(i) / Math.Log(2));
}
}
/// <summary>
/// Returns the Leading Zero Count (lzc) of the <paramref name="value"/> for its binary representation.
/// </summary>
/// <param name="value">The value to find the number of leading zeros</param>
/// <returns>The number of leading zeros.</returns>
public static int NumberOfLeadingZeros(long value)
{
//Optimisation for 32 bit values. So values under 00:16:41.0 when measuring with Stopwatch.GetTimestamp()*, we will hit a fast path.

Просмотреть файл

@ -8,6 +8,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace HdrHistogram.Utilities
{
@ -83,7 +84,7 @@ namespace HdrHistogram.Utilities
{
return GetAndIncrement(ref _startEpoch);
}
/// <summary>
/// Indicate exit from a critical section containing a write operation.
/// </summary>
@ -105,7 +106,7 @@ namespace HdrHistogram.Utilities
GetAndIncrement(ref _evenEndEpoch);
}
}
/// <summary>
/// Enter to a critical section containing a read operation (mutually excludes against other <see cref="ReaderLock()"/> calls).
/// <see cref="ReaderLock"/> DOES NOT provide synchronization against <see cref="WriterCriticalSectionEnter"/> calls.
@ -123,7 +124,7 @@ namespace HdrHistogram.Utilities
{
Monitor.Exit(_readerLock);
}
/// <summary>
/// Flip a phase in the <see cref="WriterReaderPhaser"/> instance, <see cref="FlipPhase(System.TimeSpan)"/> can only be called while holding the <see cref="ReaderLock()"/>.
@ -179,13 +180,15 @@ namespace HdrHistogram.Utilities
}
if (!caughtUp)
{
//TODO: Revist this and check if a SpinWiat is actually preferable here? -LC
if (yieldPeriod == TimeSpan.Zero)
{
Thread.Yield();
Task.Yield().GetAwaiter().GetResult();
}
else
{
Thread.Sleep(yieldPeriod);
//Thread.Sleep(yieldPeriod);
Task.Delay(yieldPeriod).GetAwaiter().GetResult();
}
}
} while (!caughtUp);

Просмотреть файл

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="AspNet VNext (CI Builds)" value="https://www.myget.org/F/aspnetvnext/api/v2" />
<add key="NuGet.org (v2)" value="https://www.nuget.org/api/v2" />
</packageSources>
</configuration>