ogxd / gxhash

The fastest hashing algorithm 📈
https://docs.rs/gxhash
MIT License
700 stars 23 forks source link

C# version #5

Closed Genbox closed 8 months ago

Genbox commented 8 months ago

I saw your post on https://github.com/dotnet/runtime/issues/85206 about a C# port. Are you able to share it? I'd like to benchmark it both in terms of speed and correctness.

ogxd commented 8 months ago

Hi @Genbox ! I'm glad to see it had someone attention 😊 I've done my best to test it thoroughly, but having someone else give it a spin would be awesome. Really curious to see how it holds up in your benchmarks and open to any feedback you've got.

I'll create a new repository tomorrow so I can share the source code and push improvements until it matches this rust implementation performance-wise. I'll also include a few basic tests. I'll keep you updated here!

ogxd commented 8 months ago

Here it is: gxhash-csharp

Actual implementation of the algorithm is here: https://github.com/ogxd/gxhash-csharp/blob/main/GxHash/GxHash.cs

I have added a few more optimization. It might not be "the most optimal" but I think it is at least conform to the spec and it already outperforms XxH3 and Marvin both on my MacBook m1 pro (ARM) and my x86 machine.

Here are the benchmark results on a github runner: https://github.com/ogxd/gxhash-csharp/actions/runs/6888604880/job/18737919394#step:7:5179

|   Method |                Value |         Mean |     Error |    StdDev | Ratio |  Thoughput (MiB/s) |
|--------- |--------------------- |-------------:|----------:|----------:|------:|-------------------:|
|   Marvin |                   zk |     3.405 ns | 0.0041 ns | 0.0037 ns |  1.00 |     1120.19 ± 2.72 |
|     XxH3 |                   zk |     3.756 ns | 0.0058 ns | 0.0048 ns |  1.10 |     1015.52 ± 3.12 |
| GxHash32 |                   zk |     1.592 ns | 0.0130 ns | 0.0108 ns |  0.47 |    2396.34 ± 39.01 |
|          |                      |              |           |           |       |                    |
|   Marvin |                 9Iza |     4.345 ns | 0.0113 ns | 0.0106 ns |  1.00 |     1756.08 ± 9.15 |
|     XxH3 |                 9Iza |     3.765 ns | 0.0132 ns | 0.0117 ns |  0.87 |    2026.15 ± 14.19 |
| GxHash32 |                 9Iza |     1.573 ns | 0.0149 ns | 0.0140 ns |  0.36 |    4849.14 ± 92.00 |
|          |                      |              |           |           |       |                    |
|   Marvin |             kwqYIEC7 |     6.418 ns | 0.0325 ns | 0.0304 ns |  1.00 |    2377.46 ± 24.07 |
|     XxH3 |             kwqYIEC7 |     4.048 ns | 0.0077 ns | 0.0068 ns |  0.63 |    3769.81 ± 14.32 |
| GxHash32 |             kwqYIEC7 |     1.568 ns | 0.0112 ns | 0.0105 ns |  0.24 |   9732.41 ± 139.11 |
|          |                      |              |           |           |       |                    |
|   Marvin |     F78AHeD7ke7NXlbK |    11.359 ns | 0.0203 ns | 0.0180 ns |  1.00 |     2686.68 ± 9.62 |
|     XxH3 |     F78AHeD7ke7NXlbK |     5.089 ns | 0.0147 ns | 0.0115 ns |  0.45 |    5996.70 ± 34.69 |
| GxHash32 |     F78AHeD7ke7NXlbK |     1.570 ns | 0.0161 ns | 0.0142 ns |  0.14 |  19432.46 ± 397.67 |
|          |                      |              |           |           |       |                    |
|   Marvin | miyOG(...)x0a2k [32] |    23.576 ns | 0.0247 ns | 0.0207 ns |  1.00 |     2588.92 ± 5.43 |
|     XxH3 | miyOG(...)x0a2k [32] |     7.288 ns | 0.0215 ns | 0.0201 ns |  0.31 |    8374.39 ± 49.46 |
| GxHash32 | miyOG(...)x0a2k [32] |     4.173 ns | 0.0202 ns | 0.0179 ns |  0.18 |  14626.85 ± 141.46 |
|          |                      |              |           |           |       |                    |
|   Marvin | KFngE(...)Gouqd [64] |    48.463 ns | 0.1138 ns | 0.0889 ns |  1.00 |    2518.86 ± 11.83 |
|     XxH3 | KFngE(...)Gouqd [64] |    11.185 ns | 0.0364 ns | 0.0341 ns |  0.23 |   10913.33 ± 71.03 |
| GxHash32 | KFngE(...)Gouqd [64] |     4.445 ns | 0.0284 ns | 0.0252 ns |  0.09 |  27461.83 ± 351.28 |
|          |                      |              |           |           |       |                    |
|   Marvin |  xo29(...)ve8s [128] |    97.237 ns | 0.0407 ns | 0.0339 ns |  1.00 |     2510.77 ± 2.10 |
|     XxH3 |  xo29(...)ve8s [128] |    31.846 ns | 0.0908 ns | 0.0758 ns |  0.33 |    7666.24 ± 43.72 |
| GxHash32 |  xo29(...)ve8s [128] |     5.933 ns | 0.0276 ns | 0.0258 ns |  0.06 |  41147.54 ± 383.13 |
|          |                      |              |           |           |       |                    |
|   Marvin |  5RmW(...)eRI6 [256] |   196.412 ns | 0.2916 ns | 0.2435 ns |  1.00 |     2486.01 ± 7.38 |
|     XxH3 |  5RmW(...)eRI6 [256] |    39.070 ns | 0.3471 ns | 0.3077 ns |  0.20 |  12497.51 ± 222.10 |
| GxHash32 |  5RmW(...)eRI6 [256] |     8.568 ns | 0.0386 ns | 0.0323 ns |  0.04 |  56986.44 ± 513.84 |
|          |                      |              |           |           |       |                    |
|   Marvin |  cO0w(...)mE36 [512] |   395.916 ns | 0.1137 ns | 0.1008 ns |  1.00 |     2466.59 ± 1.42 |
|     XxH3 |  cO0w(...)mE36 [512] |    53.312 ns | 0.2560 ns | 0.2395 ns |  0.13 |  18317.93 ± 175.94 |
| GxHash32 |  cO0w(...)mE36 [512] |    15.647 ns | 0.2386 ns | 0.2232 ns |  0.04 | 62410.91 ± 1904.05 |
|          |                      |              |           |           |       |                    |
|   Marvin | rGhG(...)cN5i [1024] |   791.511 ns | 0.2188 ns | 0.1940 ns |  1.00 |     2467.59 ± 1.36 |
|     XxH3 | rGhG(...)cN5i [1024] |   125.569 ns | 1.5008 ns | 1.4039 ns |  0.16 |  15554.23 ± 371.87 |
| GxHash32 | rGhG(...)cN5i [1024] |    30.506 ns | 0.0701 ns | 0.0547 ns |  0.04 |  64023.71 ± 294.32 |
|          |                      |              |           |           |       |                    |
|   Marvin | TsQ0(...)JE2A [2048] | 1,582.867 ns | 0.4458 ns | 0.3722 ns |  1.00 |     2467.83 ± 1.39 |
|     XxH3 | TsQ0(...)JE2A [2048] |   247.750 ns | 1.5069 ns | 1.4096 ns |  0.16 |  15766.90 ± 191.81 |
| GxHash32 | TsQ0(...)JE2A [2048] |    59.770 ns | 0.4577 ns | 0.4057 ns |  0.04 | 65355.01 ± 1000.91 |
|          |                      |              |           |           |       |                    |
|   Marvin | OZYE(...)yROZ [4096] | 3,165.447 ns | 1.7277 ns | 1.5316 ns |  1.00 |     2468.06 ± 2.69 |
|     XxH3 | OZYE(...)yROZ [4096] |   500.590 ns | 0.4903 ns | 0.4094 ns |  0.16 |   15606.59 ± 30.57 |
| GxHash32 | OZYE(...)yROZ [4096] |   111.149 ns | 0.1242 ns | 0.1037 ns |  0.04 |  70288.65 ± 157.13 |
|          |                      |              |           |           |       |                    |
|   Marvin | F2fW(...)I1XD [8192] | 6,330.805 ns | 1.5850 ns | 1.4050 ns |  1.00 |     2468.09 ± 1.24 |
|     XxH3 | F2fW(...)I1XD [8192] | 1,017.953 ns | 5.8021 ns | 5.4273 ns |  0.16 |  15349.43 ± 174.98 |
| GxHash32 | F2fW(...)I1XD [8192] |   223.868 ns | 2.1845 ns | 2.0434 ns |  0.04 | 69795.58 ± 1362.24 |
Genbox commented 8 months ago

Thanks Olivier. I'll check it out. Closing this issue for now.