project files added and fixed
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
|
||||
<LangVersion>12</LangVersion>
|
||||
<BenchmarkDotNet>0.13.1</BenchmarkDotNet>
|
||||
<MicrosoftSdk>17.2.0</MicrosoftSdk>
|
||||
<xUnit>2.4.1</xUnit>
|
||||
<xUnitRunner>2.4.5</xUnitRunner>
|
||||
<xUnitTool>2.3.1</xUnitTool>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNet)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DTLib.XXHash\DTLib.XXHash.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
DTLib.XXHash.PerformanceTest/Program.cs
Normal file
13
DTLib.XXHash.PerformanceTest/Program.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace DTLib.XXHash.PerformanceTest
|
||||
{
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BenchmarkRunner.Run<xxHashBenchmark>();
|
||||
BenchmarkRunner.Run<UtilsBenchmark>();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
DTLib.XXHash.PerformanceTest/UtilsBenchmark.cs
Normal file
39
DTLib.XXHash.PerformanceTest/UtilsBenchmark.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace DTLib.XXHash.PerformanceTest
|
||||
{
|
||||
using System;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
[RPlotExporter, RankColumn]
|
||||
[MinColumn, MaxColumn]
|
||||
[MemoryDiagnoser]
|
||||
public class UtilsBenchmark
|
||||
{
|
||||
private byte[] src;
|
||||
private byte[] des;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
src = new byte[32];
|
||||
des = new byte[32];
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void ArrayCopy()
|
||||
{
|
||||
Array.Copy(src, 0, des, 0, 32);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void BufferCopy()
|
||||
{
|
||||
Buffer.BlockCopy(src, 0, des, 0, 32);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void UnsafeBufferCopy()
|
||||
{
|
||||
Utils.BlockCopy(src, 0, des, 0, 32);
|
||||
}
|
||||
}
|
||||
}
|
||||
102
DTLib.XXHash.PerformanceTest/xxHashBenchmark.cs
Normal file
102
DTLib.XXHash.PerformanceTest/xxHashBenchmark.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
namespace DTLib.XXHash.PerformanceTest
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
|
||||
[RPlotExporter, RankColumn]
|
||||
[MinColumn, MaxColumn]
|
||||
[MemoryDiagnoser]
|
||||
// [DisassemblyDiagnoser(printAsm: true, printSource: true)]
|
||||
public class xxHashBenchmark
|
||||
{
|
||||
const int KB = 1024;
|
||||
const int MB = 1024 * KB;
|
||||
const int GB = 1024 * MB;
|
||||
|
||||
private byte[] data;
|
||||
private MemoryStream stream;
|
||||
|
||||
[Params(KB, MB, GB)]
|
||||
public int N;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
Random rand = new Random(42);
|
||||
|
||||
data = new byte[N];
|
||||
rand.NextBytes(data);
|
||||
stream = new MemoryStream(data);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public uint Hash32_Array()
|
||||
{
|
||||
return xxHash32.ComputeHash(data, data.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public uint Hash32_Span()
|
||||
{
|
||||
Span<byte> span = new Span<byte>(data);
|
||||
return xxHash32.ComputeHash(span, span.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public uint Hash32_ReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(data);
|
||||
return xxHash32.ComputeHash(span, span.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public uint Hash32_Stream()
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return xxHash32.ComputeHash(stream);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task<uint> Hash32_StreamAsync()
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return await xxHash32.ComputeHashAsync(stream);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public ulong Hash64_Array()
|
||||
{
|
||||
return xxHash64.ComputeHash(data, data.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public ulong Hash64_Span()
|
||||
{
|
||||
Span<byte> span = new Span<byte>(data);
|
||||
return xxHash64.ComputeHash(span, span.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public ulong Hash64_ReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(data);
|
||||
return xxHash64.ComputeHash(span, span.Length);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public ulong Hash64_Stream()
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return xxHash64.ComputeHash(stream);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task<ulong> Hash64_StreamAsync()
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return await xxHash64.ComputeHashAsync(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user