Skip to content

Commit

Permalink
Incredible Hashing Speed with Faster.Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Wsm2110 committed Nov 27, 2024
1 parent d9b2894 commit a7fb8ff
Show file tree
Hide file tree
Showing 13 changed files with 688 additions and 333 deletions.
2 changes: 1 addition & 1 deletion Faster.Map.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Faster.Map", "src\Faster.Ma
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faster.Map.Hash.Benchmark", "benchmarks\Faster.Map.Hash.Benchmark\Faster.Map.Hash.Benchmark.csproj", "{84129404-D8F5-1687-BF71-4A68D6206742}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faster.Map.Hash", "unittests\Faster.Map.Hash.Tests\Faster.Map.Hash.csproj", "{81386703-5478-35CB-C5D9-DF6D2B64F97C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faster.Map.Hash.Tests", "unittests\Faster.Map.Hash.Tests\Faster.Map.Hash.Tests.csproj", "{81386703-5478-35CB-C5D9-DF6D2B64F97C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
153 changes: 90 additions & 63 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/Faster.Map.Benchmark/AddStringBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AddStringBenchmark

#region Properties

[Params(100, 1000, 10000, 100000, 200000, 400000, 800000)]
[Params(800, 10000, 100000, 200000, 400000, 800000)]

public uint Length { get; set; }

Expand Down
68 changes: 33 additions & 35 deletions benchmarks/Faster.Map.Benchmark/GetBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class GetBenchmark

#region Properties


[Params(800000)]
[Params(100, 1000, 10000, 100000, 200000, 400000, 800000, 1000000)]
public uint Length { get; set; }

#endregion
Expand Down Expand Up @@ -64,12 +63,12 @@ public void Setup()

foreach (var key in keys)
{
//_dictionary.Add(key, key);
_dictionary.Add(key, key);
_denseMap_Default.Emplace(key, key);
//_denseMap_Xxhash3.Emplace(key, key);
_denseMap_Xxhash3.Emplace(key, key);
_denseMap_fastHash.Emplace(key, key);
_denseMap_GxHash.Emplace(key, key);
//_robinHoodMap.Emplace(key, key);
_robinHoodMap.Emplace(key, key);
}
}

Expand All @@ -83,24 +82,23 @@ public void DenseMap()
}
}


//[Benchmark]
//public void DenseMap_XXhash3()
//{
// for (int i = 0; i < Length; ++i)
// {
// var key = keys[i];
// _denseMap_Xxhash3.Get(key, out var _);
// }
//}
[Benchmark]
public void DenseMap_XXhash3()
{
for (int i = 0; i < Length; ++i)
{
var key = keys[i];
_denseMap_Xxhash3.Get(key, out var _);
}
}

[Benchmark]
public void DenseMap_FastHash()
{
for (int i = 0; i < Length; ++i)
{
var key = keys[i];
_denseMap_fastHash.Get(key, out var _);
_denseMap_fastHash.Get(key, out var _);
}
}

Expand All @@ -114,24 +112,24 @@ public void DenseMap_GxHash()
}
}

//[Benchmark]
//public void RobinhoodMap()
//{
// for (int i = 0; i < Length; ++i)
// {
// var key = keys[i];
// _robinHoodMap.Get(key, out var _);
// }
//}

//[Benchmark(Baseline = true)]
//public void Dictionary()
//{
// for (int i = 0; i < Length; ++i)
// {
// var key = keys[i];
// _dictionary.TryGetValue(key, out var _);
// }
//}
[Benchmark]
public void RobinhoodMap()
{
for (int i = 0; i < Length; ++i)
{
var key = keys[i];
_robinHoodMap.Get(key, out var _);
}
}

[Benchmark(Baseline = true)]
public void Dictionary()
{
for (int i = 0; i < Length; ++i)
{
var key = keys[i];
_dictionary.TryGetValue(key, out var _);
}
}
}
}
2 changes: 1 addition & 1 deletion benchmarks/Faster.Map.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<AddStringBenchmark>(new DebugInProcessConfig());
BenchmarkRunner.Run<GetBenchmark>();
//BenchmarkRunner.Run<AddAndResizeBenchmark>();
//BenchmarkRunner.Run<UpdateBenchmark>();
//BenchmarkRunner.Run<RemoveBenchmark>();
Expand Down
40 changes: 35 additions & 5 deletions benchmarks/Faster.Map.Benchmark/RemoveBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class RemoveBenchmark
private DenseMap<uint, uint> _denseMap;
private Dictionary<uint, uint> _dictionary;
private RobinhoodMap<uint, uint> _robinhoodMap;

private DenseMap<uint, uint> _denseMapxxHash;

Check warning on line 21 in benchmarks/Faster.Map.Benchmark/RemoveBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Field 'RemoveBenchmark._denseMapxxHash' is never assigned to, and will always have its default value null
private DenseMap<uint, uint> _denseMapGxHash;

Check warning on line 22 in benchmarks/Faster.Map.Benchmark/RemoveBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Field 'RemoveBenchmark._denseMapGxHash' is never assigned to, and will always have its default value null
private DenseMap<uint, uint> _denseMapFastHash;

Check warning on line 23 in benchmarks/Faster.Map.Benchmark/RemoveBenchmark.cs

View workflow job for this annotation

GitHub Actions / build

Field 'RemoveBenchmark._denseMapFastHash' is never assigned to, and will always have its default value null

private uint[] keys;

#endregion
Expand All @@ -44,10 +47,7 @@ public void Setup()
for (var index = 0; index < Length; index++)
{
keys[index] = uint.Parse(splittedOutput[index]);
}


// Shuffle(new Random(), keys);
}
}

[IterationSetup]
Expand All @@ -65,6 +65,9 @@ public void IterationSetupX()
{
_dictionary.Add(key, key);
_denseMap.Emplace(key, key);
_denseMapxxHash.Emplace(key, key);
_denseMapGxHash.Emplace(key, key);
_denseMapFastHash.Emplace(key, key);
_robinhoodMap.Emplace(key, key);
}
}
Expand All @@ -80,6 +83,33 @@ public void DenseMap()
}
}

[Benchmark]
public void DenseMap_Xxhash3()
{
foreach (var key in keys)
{
_denseMapxxHash.Remove(key);
}
}

[Benchmark]
public void DenseMap_GxHash()
{
foreach (var key in keys)
{
_denseMapGxHash.Remove(key);
}
}

[Benchmark]
public void DenseMap_FastHash()
{
foreach (var key in keys)
{
_denseMapFastHash.Remove(key);
}
}

[Benchmark]
public void RobinhoodMap()
{
Expand Down
93 changes: 47 additions & 46 deletions benchmarks/Faster.Map.Benchmark/StringBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class StringBenchmark
private DenseMap<string, string> _denseMap;
private DenseMap<string, string> _denseMapxxHash;
private DenseMap<string, string> _denseMapGxHash;
private DenseMap<string, string> _denseMapFastHash;
private DenseMap<string, string> _denseMapFastHash;
private Dictionary<string, string> _dictionary;
private RobinhoodMap<string, string> _robinhoodMap;

Expand All @@ -29,7 +29,7 @@ public class StringBenchmark

#region Properties

[Params(100, 1000, 10000, 100000, 200000, 400000, 800000, 1000000)]
[Params(/*100, 1000, 10000, 100000, 200000, 400000, 800000,*/ 1000000)]
public uint Length { get; set; }

#endregion
Expand Down Expand Up @@ -74,32 +74,32 @@ public void Setup()

}

[Benchmark]
public void DenseMap_Default()
{
foreach (var key in keys)
{
_denseMap.Get(key, out var result);
}
}

[Benchmark]
public void DenseMap_Xxhash3()
{
foreach (var key in keys)
{
_denseMapxxHash.Get(key, out var result);
}
}

[Benchmark]
public void DenseMap_GxHash()
{
foreach (var key in keys)
{
_denseMapGxHash.Get(key, out var result);
}
}
//[Benchmark]
//public void DenseMap_Default()
//{
// foreach (var key in keys)
// {
// _denseMap.Get(key, out var result);
// }
//}

//[Benchmark]
//public void DenseMap_Xxhash3()
//{
// foreach (var key in keys)
// {
// _denseMapxxHash.Get(key, out var result);
// }
//}

//[Benchmark]
//public void DenseMap_GxHash()
//{
// foreach (var key in keys)
// {
// _denseMapGxHash.Get(key, out var result);
// }
//}

[Benchmark]
public void DenseMap_FastHash()
Expand All @@ -108,25 +108,26 @@ public void DenseMap_FastHash()
{
_denseMapFastHash.Get(key, out var result);
}
}
//}

//[Benchmark]
//public void RobinhoodMap()
//{
// foreach (var key in keys)
// {
// _robinhoodMap.Get(key, out var result);
// }
//}

//[Benchmark]
//public void Dictionary()
//{
// foreach (var key in keys)
// {
// _dictionary.TryGetValue(key, out var result);
// }
//}

[Benchmark]
public void RobinhoodMap()
{
foreach (var key in keys)
{
_robinhoodMap.Get(key, out var result);
}
}

[Benchmark]
public void Dictionary()
{
foreach (var key in keys)
{
_dictionary.TryGetValue(key, out var result);
}
}

}
}
4 changes: 2 additions & 2 deletions benchmarks/Faster.Map.Hash.Benchmark/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class Benchmark
private FastHash _hash = new FastHash();
private string source;

Check warning on line 14 in benchmarks/Faster.Map.Hash.Benchmark/Benchmark.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'source' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

[Params(10, 16, 32, 48, 100)]
[Params(1000)]
public uint StringLength { get; set; }

[Params(10, 100, 1000, 10000)]
[Params(10000)]
public uint Iterations { get; set; }

[GlobalSetup]
Expand Down
31 changes: 21 additions & 10 deletions src/Faster.Map.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<CopyRight>MIT</CopyRight>
<PackageReleaseNotes>
New Features:

Add custom hasher:

- GxHash
- XX3Hash
- XX3HashString
✨ What’s New?
🏎️ Incredible Hashing Speed with Faster.Hash

Optimized Performance: Harnesses hardware-accelerated AES instructions for lightning-fast hashing.
Deterministic and Reliable: Ensures consistent and collision-resistant hashes for uint, ulong, and arbitrary byte spans.
Highly Flexible: Hash support for various data types:
HashU64(uint source): Quickly hash 32-bit integers.
HashU64(ulong source): Hash 64-bit integers with efficiency.
HashU64(ReadOnlyspan): Process byte arrays with incredible speed.

🗂️ Map Enhancements

Seamlessly integrates with Faster.Hash to deliver high-speed key lookups and optimized map operations.
Improved handling of large datasets with reduced memory overhead and faster hash-based operations.

🛡️ Secure Hashing with HashU64Secure

Generate stronger hashes with additional randomness and encryption rounds for scenarios requiring enhanced data integrity.

</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/Wsm2110/Faster.Map</PackageProjectUrl>
<AssemblyVersion>6.1.2</AssemblyVersion>
<FileVersion>6.1.2</FileVersion>
<AssemblyVersion>6.1.3</AssemblyVersion>
<FileVersion>6.1.3</FileVersion>
<Title>Fastest .net hashmap</Title>
<Version>6.1.2</Version>
<Version>6.1.3</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>
Incredibly fast (concurrent) hashmap
Expand Down
Loading

0 comments on commit a7fb8ff

Please sign in to comment.