Skip to content

Commit

Permalink
Merge pull request #58 from LeeCampbell/NetStandardSupport
Browse files Browse the repository at this point in the history
Net standard support
  • Loading branch information
LeeCampbell authored Jun 20, 2017
2 parents 3e7ad9d + 792a019 commit 1d516f9
Show file tree
Hide file tree
Showing 169 changed files with 978 additions and 2,549 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
File renamed without changes
22 changes: 22 additions & 0 deletions HdrHistogram.Benchmarking/HdrHistogram.Benchmarking.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net47;netcoreapp1.1</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<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>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions HdrHistogram.Benchmarking/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;

namespace HdrHistogram.Benchmarking
{
class Program
{
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, config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace HdrHistogram.Benchmarking.Recording
{
[Config(typeof(ExhuastiveJobWithMemoryDiagnosisConfig))]
public class Recording32BitBenchmark
{
private readonly long[] _testValues;
Expand Down
12 changes: 12 additions & 0 deletions HdrHistogram.Examples/HdrHistogram.Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ private static void CreateAndCloseDatagramSocket()
}
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void CreateAndCloseDatagramSocket()

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -25,7 +25,7 @@ public void Can_support_multiple_concurrent_recorders()
.ToArray();
Parallel.Invoke(actions);

Assert.AreEqual(expected, target.TotalCount);
Assert.Equal(expected, target.TotalCount);
}
}
}
101 changes: 101 additions & 0 deletions HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<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>
<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\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\ycsb.logV1.hlog" />
</ItemGroup>

<ItemGroup>
<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>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -27,15 +28,15 @@ public void PercentileDistrubution_hgrm_output_is_in_correct_format(
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);
Expand All @@ -47,10 +48,10 @@ public void PercentileDistrubution_csv_output_is_in_correct_format(
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");
Expand All @@ -76,13 +77,13 @@ public void OnlySingleValueFlaggedAsLastValue()
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);
}
Expand Down
55 changes: 55 additions & 0 deletions HdrHistogram.UnitTests/HistogramAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Linq;
using FluentAssertions;
using HdrHistogram.Iteration;
using Xunit;

namespace HdrHistogram.UnitTests
{
public static class HistogramAssert
{
public static void AreEqual(HistogramBase expected, HistogramBase actual)
{
Assert.Equal(expected.GetType(), actual.GetType());
AreValueEqual(expected, actual);
}

public static void AreValueEqual(HistogramBase expected, HistogramBase actual)
{
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();
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}");
}
}
}
}
}
Loading

0 comments on commit 1d516f9

Please sign in to comment.