Skip to content

CI test - #133526

Draft
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:xxhash-perf
Draft

CI test#133526
MihaZupan wants to merge 1 commit into
dotnet:mainfrom
MihaZupan:xxhash-perf

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

No description provided.

@MihaZupan MihaZupan added this to the 12.0.0 milestone Sep 9, 2026
@MihaZupan MihaZupan self-assigned this Sep 9, 2026
@MihaZupan MihaZupan added the NO-REVIEW Experimental/testing PR, do NOT review it label Sep 9, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-hashing, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@MihaZupan

This comment was marked as outdated.

@MihaZupan

Copy link
Copy Markdown
Member Author

@EgorBot -amd -ubuntu24_azure_cobalt100 -osx_arm64

using System;
using System.IO.Hashing;
using BenchmarkDotNet.Attributes;

[MemoryDiagnoser]
public class XxHashBenchmarks
{
    private const int BatchSize = 65_536;
    private byte[] _data = null!;
    private int[] _lengths = null!;

    // Bytes. -1: random 0..240; -2: random 0..4096.
    [Params(0, 16, 17, 32, 33, 64, 65, 96, 97, 128, 129, 240, 241,
        1024, 1025, 16384, -1, -2)]
    public int Length { get; set; }

    [Params(0L, 42L)]
    public long Seed { get; set; }

    [GlobalSetup]
    public void Setup()
    {
        int maximumLength = Length switch
        {
            -1 => 240,
            -2 => 4096,
            _ => Length
        };

        _data = new byte[maximumLength];
        new Random(43).NextBytes(_data);

        Random random = new Random(42);
        _lengths = new int[BatchSize];
        for (int i = 0; i < _lengths.Length; i++)
        {
            _lengths[i] = Length < 0
                ? random.Next(maximumLength + 1)
                : Length;
        }
    }

    [Benchmark(OperationsPerInvoke = BatchSize)]
    public ulong XxHash3_OneShot()
    {
        ulong result = 0;
        foreach (int length in _lengths)
        {
            result = unchecked(
                result + XxHash3.HashToUInt64(_data.AsSpan(0, length), Seed));
        }
        return result;
    }

    [Benchmark(OperationsPerInvoke = BatchSize)]
    public UInt128 XxHash128_OneShot()
    {
        UInt128 result = 0;
        foreach (int length in _lengths)
        {
            result = unchecked(
                result + XxHash128.HashToUInt128(_data.AsSpan(0, length), Seed));
        }
        return result;
    }
}

Note

Benchmark prepared with GitHub Copilot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO.Hashing NO-REVIEW Experimental/testing PR, do NOT review it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant