uranium62/xxHash

Comparison to other xxHash libraries

witcher112 opened this issue · 1 comments

Hello!

First of all, thank you for sharing your code :)

Why? I think that results below speak for themselves :D

                                            Method |       Mean |     Error |    StdDev |
---------------------------------------------------|-----------:|----------:|----------:|
  System.Data.HashFunction.xxHash 2.0.0            | 7,866.3 ms | 66.149 ms | 61.875 ms |
  Extensions.Data.xxHash.core20 1.0.2.1 (XXHash32) | 7,834.1 ms | 70.787 ms | 66.214 ms |
  Extensions.Data.xxHash.core20 1.0.2.1 (XXHash64) | 4,234.4 ms | 18.427 ms | 17.237 ms |
  Standart.Hash.xxHash 1.0.6 (xxHash64)            |   679.1 ms |  4.434 ms |  4.147 ms |
  Standart.Hash.xxHash 1.0.6 (xxHash32)            | 1,201.7 ms |  7.507 ms |  7.022 ms |

I used BenchmarkDotNet to create this little comparison. Test file was of 1.8 GiB size. Feel free to use it anywhere you want.

If you'd like to test it by yourself, here's source code:

using System.Data.HashFunction.xxHash;
using System.IO;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using Extensions.Data;
using Standart.Hash.xxHash;

namespace XXHashBenchmark
{
public class Program
{
    public class AllowNonOptimized : ManualConfig
    {
        public AllowNonOptimized()
        {
            Add(
                JitOptimizationsValidator
                    .DontFailOnError); // ALLOW NON-OPTIMIZED DLLS

            Add(
                DefaultConfig.Instance.GetLoggers()
                    .ToArray()); // manual config has no loggers by default
            Add(
                DefaultConfig.Instance.GetExporters()
                    .ToArray()); // manual config has no exporters by default
            Add(
                DefaultConfig.Instance.GetColumnProviders()
                    .ToArray()); // manual config has no columns by default
        }
    }

    public class XxHashBenchmark
    {
        private const string FilePath = "file2";

        private FileStream GetStream()
        {
            return new FileStream(
                FilePath,
                FileMode.Open);
        }

        [Benchmark]
        public void Func1()
        {
            using (var stream = GetStream())
            {
                var x = xxHashFactory.Instance.Create(
                    new xxHashConfig
                    {
                        Seed = 42
                    });

                x.ComputeHash(stream);
            }
        }

        [Benchmark]
        public void Func2()
        {
            var x = XXHash32.Create(42);

            using (var stream = GetStream())
            {
                x.ComputeHash(stream);
            }
        }
        
        [Benchmark]
        public void Func3()
        {
            var x = XXHash64.Create(42);

            using (var stream = GetStream())
            {
                x.ComputeHash(stream);
            }
        }
        
        [Benchmark]
        public void Func4()
        {
            using (var stream = GetStream())
            {
                xxHash64.ComputeHash(stream);
            }
        }
        
        [Benchmark]
        public void Func5()
        {
            using (var stream = GetStream())
            {
                xxHash32.ComputeHash(stream);
            }
        }
    }

    public static void Main(string[] args)
    {
        BenchmarkRunner.Run<XxHashBenchmark>(new AllowNonOptimized());
    }
}
}

Cheers!