diff --git a/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report-github.md b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report-github.md new file mode 100644 index 0000000..aac0428 --- /dev/null +++ b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report-github.md @@ -0,0 +1,29 @@ +``` + +BenchmarkDotNet v0.13.8, Windows 11 (10.0.22621.2283/22H2/2022Update/SunValley2) +Intel Core i7-8700 CPU 3.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores +.NET SDK 8.0.100-rc.1.23463.5 + [Host] : .NET 7.0.11 (7.0.1123.42427), X64 RyuJIT AVX2 + Core70 : .NET 7.0.11 (7.0.1123.42427), X64 RyuJIT AVX2 + Core80 : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2 + + +``` +| Method | Job | Runtime | Bits | Mean | Error | StdDev | Gen0 | Allocated | +|---------- |------- |--------- |----- |-----------:|---------:|---------:|-----------:|-----------:| +| **Murmur3** | **Core70** | **.NET 7.0** | **4** | **2,145.8 ms** | **28.16 ms** | **24.96 ms** | **34000.0000** | **2441.41 MB** | +| Fnv1A | Core70 | .NET 7.0 | 4 | 1,062.2 ms | 10.78 ms | 9.55 ms | 10000.0000 | 762.95 MB | +| XxHash64 | Core70 | .NET 7.0 | 4 | 861.5 ms | 7.19 ms | 6.38 ms | 13000.0000 | 1068.12 MB | +| XxHash128 | Core70 | .NET 7.0 | 4 | 782.3 ms | 11.13 ms | 9.29 ms | 15000.0000 | 1144.42 MB | +| Murmur3 | Core80 | .NET 8.0 | 4 | 2,007.7 ms | 38.95 ms | 52.00 ms | 27000.0000 | 2441.41 MB | +| Fnv1A | Core80 | .NET 8.0 | 4 | 1,013.4 ms | 6.26 ms | 5.85 ms | 8000.0000 | 762.95 MB | +| XxHash64 | Core80 | .NET 8.0 | 4 | 869.7 ms | 6.63 ms | 5.88 ms | 12000.0000 | 1068.12 MB | +| XxHash128 | Core80 | .NET 8.0 | 4 | 779.6 ms | 7.87 ms | 7.36 ms | 13000.0000 | 1144.42 MB | +| **Murmur3** | **Core70** | **.NET 7.0** | **16** | **2,177.4 ms** | **42.68 ms** | **70.12 ms** | **34000.0000** | **2441.72 MB** | +| Fnv1A | Core70 | .NET 7.0 | 16 | 1,121.2 ms | 10.51 ms | 9.32 ms | 10000.0000 | 763.26 MB | +| XxHash64 | Core70 | .NET 7.0 | 16 | 909.6 ms | 17.82 ms | 28.27 ms | 14000.0000 | 1068.43 MB | +| XxHash128 | Core70 | .NET 7.0 | 16 | 825.1 ms | 16.01 ms | 22.96 ms | 15000.0000 | 1144.73 MB | +| Murmur3 | Core80 | .NET 8.0 | 16 | 2,094.1 ms | 31.54 ms | 27.96 ms | 27000.0000 | 2441.72 MB | +| Fnv1A | Core80 | .NET 8.0 | 16 | 1,098.3 ms | 21.94 ms | 23.47 ms | 8000.0000 | 763.26 MB | +| XxHash64 | Core80 | .NET 8.0 | 16 | 903.3 ms | 16.75 ms | 17.20 ms | 12000.0000 | 1068.43 MB | +| XxHash128 | Core80 | .NET 8.0 | 16 | 835.4 ms | 15.32 ms | 12.79 ms | 13000.0000 | 1144.73 MB | diff --git a/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.csv b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.csv new file mode 100644 index 0000000..44dbb52 --- /dev/null +++ b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.csv @@ -0,0 +1,17 @@ +Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Bits,Mean,Error,StdDev,Gen0,Allocated +Murmur3,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,"2,145.8 ms",28.16 ms,24.96 ms,34000.0000,2441.41 MB +Fnv1A,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,"1,062.2 ms",10.78 ms,9.55 ms,10000.0000,762.95 MB +XxHash64,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,861.5 ms,7.19 ms,6.38 ms,13000.0000,1068.12 MB +XxHash128,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,782.3 ms,11.13 ms,9.29 ms,15000.0000,1144.42 MB +Murmur3,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,"2,007.7 ms",38.95 ms,52.00 ms,27000.0000,2441.41 MB +Fnv1A,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,"1,013.4 ms",6.26 ms,5.85 ms,8000.0000,762.95 MB +XxHash64,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,869.7 ms,6.63 ms,5.88 ms,12000.0000,1068.12 MB +XxHash128,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,4,779.6 ms,7.87 ms,7.36 ms,13000.0000,1144.42 MB +Murmur3,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,"2,177.4 ms",42.68 ms,70.12 ms,34000.0000,2441.72 MB +Fnv1A,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,"1,121.2 ms",10.51 ms,9.32 ms,10000.0000,763.26 MB +XxHash64,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,909.6 ms,17.82 ms,28.27 ms,14000.0000,1068.43 MB +XxHash128,Core70,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 7.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,825.1 ms,16.01 ms,22.96 ms,15000.0000,1144.73 MB +Murmur3,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,"2,094.1 ms",31.54 ms,27.96 ms,27000.0000,2441.72 MB +Fnv1A,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,"1,098.3 ms",21.94 ms,23.47 ms,8000.0000,763.26 MB +XxHash64,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,903.3 ms,16.75 ms,17.20 ms,12000.0000,1068.43 MB +XxHash128,Core80,False,Default,Default,Default,Default,Default,Default,111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 8.0,False,True,False,True,Default,Default,False,False,True,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,16,835.4 ms,15.32 ms,12.79 ms,13000.0000,1144.73 MB diff --git a/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.html b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.html new file mode 100644 index 0000000..18b4c73 --- /dev/null +++ b/CardinalityEstimation.Benchmark/BenchmarkDotNet.Artifacts/results/DifferentHashes-report.html @@ -0,0 +1,46 @@ + + + + +DifferentHashes-20230916-162923 + + + + +

+BenchmarkDotNet v0.13.8, Windows 11 (10.0.22621.2283/22H2/2022Update/SunValley2)
+Intel Core i7-8700 CPU 3.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
+.NET SDK 8.0.100-rc.1.23463.5
+  [Host] : .NET 7.0.11 (7.0.1123.42427), X64 RyuJIT AVX2
+  Core70 : .NET 7.0.11 (7.0.1123.42427), X64 RyuJIT AVX2
+  Core80 : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2
+
+
+ + + + + + + + + + + + + + + + + + + + +
MethodJobRuntimeBitsMeanErrorStdDevGen0Allocated
Murmur3Core70.NET 7.042,145.8 ms28.16 ms24.96 ms34000.00002441.41 MB
Fnv1ACore70.NET 7.041,062.2 ms10.78 ms9.55 ms10000.0000762.95 MB
XxHash64Core70.NET 7.04861.5 ms7.19 ms6.38 ms13000.00001068.12 MB
XxHash128Core70.NET 7.04782.3 ms11.13 ms9.29 ms15000.00001144.42 MB
Murmur3Core80.NET 8.042,007.7 ms38.95 ms52.00 ms27000.00002441.41 MB
Fnv1ACore80.NET 8.041,013.4 ms6.26 ms5.85 ms8000.0000762.95 MB
XxHash64Core80.NET 8.04869.7 ms6.63 ms5.88 ms12000.00001068.12 MB
XxHash128Core80.NET 8.04779.6 ms7.87 ms7.36 ms13000.00001144.42 MB
Murmur3Core70.NET 7.0162,177.4 ms42.68 ms70.12 ms34000.00002441.72 MB
Fnv1ACore70.NET 7.0161,121.2 ms10.51 ms9.32 ms10000.0000763.26 MB
XxHash64Core70.NET 7.016909.6 ms17.82 ms28.27 ms14000.00001068.43 MB
XxHash128Core70.NET 7.016825.1 ms16.01 ms22.96 ms15000.00001144.73 MB
Murmur3Core80.NET 8.0162,094.1 ms31.54 ms27.96 ms27000.00002441.72 MB
Fnv1ACore80.NET 8.0161,098.3 ms21.94 ms23.47 ms8000.0000763.26 MB
XxHash64Core80.NET 8.016903.3 ms16.75 ms17.20 ms12000.00001068.43 MB
XxHash128Core80.NET 8.016835.4 ms15.32 ms12.79 ms13000.00001144.73 MB
+ + diff --git a/CardinalityEstimation.Benchmark/CardinalityEstimation.Benchmark.csproj b/CardinalityEstimation.Benchmark/CardinalityEstimation.Benchmark.csproj index 32bb7df..d2b675e 100644 --- a/CardinalityEstimation.Benchmark/CardinalityEstimation.Benchmark.csproj +++ b/CardinalityEstimation.Benchmark/CardinalityEstimation.Benchmark.csproj @@ -2,7 +2,7 @@ Exe - net8.0;net7.0 + net8.0;net7.0;net6.0 enable enable true @@ -11,7 +11,7 @@ - + diff --git a/CardinalityEstimation.Benchmark/Program.cs b/CardinalityEstimation.Benchmark/Program.cs index ade67ca..afa2432 100644 --- a/CardinalityEstimation.Benchmark/Program.cs +++ b/CardinalityEstimation.Benchmark/Program.cs @@ -16,7 +16,7 @@ public class DifferentHashes { public static readonly Random Rand = new Random(); - private const int N = 1000; + private const int N = 10000000; private string[] dataStrings = Enumerable.Range(0, N).Select(_ => Rand.Next().ToString() + Guid.NewGuid().ToString() + Rand.Next().ToString()).ToArray(); @@ -28,7 +28,7 @@ public class DifferentHashes [Benchmark] public void Fnv1A() => Run(Bits, CardinalityEstimation.Hash.Fnv1A.GetHashCode); [Benchmark] - public void XxHash64() => Run(Bits, (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash64.Hash(x))); + public void XxHash128() => Run(Bits, (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x))); private void Run(int bits, GetHashCodeDelegate hashFunction) @@ -46,7 +46,7 @@ public class GetBytesTests { public static readonly Random Rand = new Random(); - private const int N = 1000; + private const int N = 10000000; private int[] dataInts = Enumerable.Range(0, N).Select(_ => Rand.Next()).ToArray(); diff --git a/CardinalityEstimation/CardinalityEstimation.csproj b/CardinalityEstimation/CardinalityEstimation.csproj index 0efb225..27c71bb 100644 --- a/CardinalityEstimation/CardinalityEstimation.csproj +++ b/CardinalityEstimation/CardinalityEstimation.csproj @@ -31,6 +31,11 @@ true + + + + + diff --git a/CardinalityEstimation/CardinalityEstimator.cs b/CardinalityEstimation/CardinalityEstimator.cs index 5b80b7b..801ee9e 100644 --- a/CardinalityEstimation/CardinalityEstimator.cs +++ b/CardinalityEstimation/CardinalityEstimator.cs @@ -179,7 +179,15 @@ internal CardinalityEstimator(GetHashCodeDelegate hashFunction, CardinalityEstim subAlgorithmSelectionThreshold = GetSubAlgorithmSelectionThreshold(bitsPerIndex); // Init the hash function - this.hashFunction = hashFunction ?? Murmur3.GetHashCode; + this.hashFunction = hashFunction; + if (this.hashFunction == null) + { +#if NET8_0_OR_GREATER + hashFunction = (x) => BitConverter.ToUInt64(System.IO.Hashing.XxHash128.Hash(x)); +#else + hashFunction = Murmur3.GetHashCode; +#endif + } // Init the direct count directCount = state.DirectCount != null ? new HashSet(state.DirectCount) : null; @@ -214,7 +222,7 @@ internal CardinalityEstimator(GetHashCodeDelegate hashFunction, CardinalityEstim directCount = null; } } - #endregion +#endregion #region Public properties public ulong CountAdditions { get; private set; }