Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MihaZupan
Copy link
Member

public class ProbMap
{
    private static readonly SearchValues<char> s_values = SearchValues.Create("űßčšžć");
    private string _text = null!;

    [Params(15, 16, 64, 1000, 10_000)] public int Length;
    [GlobalSetup] public void Setup() => _text = new string('\n', Length);
    [Benchmark] public int LastIndexOfAny() => _text.AsSpan().LastIndexOfAny(s_values);
}
Method Toolchain Length Mean Error Ratio
LastIndexOfAny main 15 13.153 ns 0.0102 ns 1.00
LastIndexOfAny pr 15 13.489 ns 0.0047 ns 1.03
LastIndexOfAny main 16 14.007 ns 0.0111 ns 1.00
LastIndexOfAny pr 16 4.009 ns 0.0016 ns 0.29
LastIndexOfAny main 64 55.305 ns 0.0825 ns 1.00
LastIndexOfAny pr 64 4.962 ns 0.0011 ns 0.09
LastIndexOfAny main 1000 865.996 ns 0.0793 ns 1.00
LastIndexOfAny pr 1000 66.446 ns 0.0127 ns 0.08
LastIndexOfAny main 10000 8,524.580 ns 2.8686 ns 1.00
LastIndexOfAny pr 10000 628.016 ns 0.0698 ns 0.07
public class ProbMap
{
    private static readonly SearchValues<char> s_probMap = SearchValues.Create("űßčšžć");
    private static readonly SearchValues<char> s_asciiWithProbMap = SearchValues.Create("aeiouű");
    private string _text = new string('ű', 100);

    [Benchmark] public int EarlyMatch() => _text.AsSpan().LastIndexOfAny(s_probMap);
    [Benchmark] public int EarlyMatchWithAscii() => _text.AsSpan().LastIndexOfAny(s_asciiWithProbMap);
}
Method Toolchain Mean Error Ratio
EarlyMatch main 1.438 ns 0.0007 ns 1.00
EarlyMatch pr 8.607 ns 0.0089 ns 5.99
EarlyMatchWithAscii main 2.927 ns 0.0042 ns 1.00
EarlyMatchWithAscii pr 9.159 ns 0.0019 ns 3.13

@MihaZupan MihaZupan added this to the 9.0.0 milestone May 16, 2024
@MihaZupan MihaZupan requested a review from stephentoub May 16, 2024 17:43
@MihaZupan MihaZupan self-assigned this May 16, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-buffers
See info in area-owners.md if you want to be subscribed.

@MihaZupan MihaZupan merged commit 68ae561 into dotnet:main May 17, 2024
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
* Vectorize ProbabilisticMap.LastIndexOfAny

* Fix loop in TryFindLastMatchOverlapped

* Use Avx512 name suffix with more helpers
@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants