Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TryParseUInt32HexNumberStyle directly from Guid.TryParse #44918

Merged
merged 1 commit into from
Nov 20, 2020

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Nov 19, 2020

Skips public entry points of uint.TryParse, including argument validation, branches for style, but most impactfully fetching the current number culture when it won't actually be needed.

Noticed while looking at startup costs, as it was causing current culture to be initialized unexpectedly.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
using System;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args);

    [Benchmark]
    public bool TryParse() => Guid.TryParse("dd16f057-4f29-495c-9f09-7201d8bee53d", out _);

    [Benchmark]
    public bool TryParseD() => Guid.TryParseExact("dd16f057-4f29-495c-9f09-7201d8bee53d", "D", out _);

    [Benchmark]
    public bool TryParseN() => Guid.TryParseExact("6e76bbd10361464b980309a281d17180", "N", out _);
}
Method Toolchain Mean Ratio
TryParse \master\corerun.exe 86.38 ns 1.00
TryParse \pr\corerun.exe 74.42 ns 0.87
TryParseD \master\corerun.exe 82.14 ns 1.00
TryParseD \pr\corerun.exe 71.21 ns 0.89
TryParseN \master\corerun.exe 96.77 ns 1.00
TryParseN \pr\corerun.exe 60.36 ns 0.62

Contributes to #44598

Skips public entry points of uint.TryParse, including argument validation, branches for style, but most impactfully fetching the current number culture when it won't actually be needed.
@stephentoub stephentoub added this to the 6.0.0 milestone Nov 19, 2020
Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we already have micro benchmark coverage?

@stephentoub stephentoub merged commit f22d7c5 into dotnet:master Nov 20, 2020
@stephentoub stephentoub deleted the guidparse branch November 20, 2020 15:40
@kunalspathak
Copy link
Member

Perf lab data shows improvements - DrewScoggins/performance-2#3513

@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants