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

Improve base64 methods on .NET 6 #712

Merged
merged 8 commits into from
Nov 6, 2024
Merged

Improve base64 methods on .NET 6 #712

merged 8 commits into from
Nov 6, 2024

Conversation

sebastienros
Copy link
Owner

No description provided.

@@ -106,7 +107,10 @@ public static ValueTask<FluidValue> Handleize(FluidValue input, FilterArguments
}
}

static bool IsCapitalLetter(char c) => c >= 'A' && c <= 'Z';
static bool IsCapitalLetter(char c)
Copy link
Collaborator

@lahma lahma Nov 6, 2024

Choose a reason for hiding this comment

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

Copy link
Owner Author

@sebastienros sebastienros Nov 6, 2024

Choose a reason for hiding this comment

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

| Method | Job               | Runtime  | Mean     | Error     | StdDev   | Allocated |
|------- |------------------ |--------- |---------:|----------:|---------:|----------:|
| M1     | ShortRun-.NET 8.0 | .NET 8.0 | 15.90 ns |  4.675 ns | 0.256 ns |         - |
| M2     | ShortRun-.NET 8.0 | .NET 8.0 | 22.86 ns | 44.572 ns | 2.443 ns |         - |
| M1     | ShortRun-.NET 9.0 | .NET 9.0 | 16.24 ns |  6.305 ns | 0.346 ns |         - |
| M2     | ShortRun-.NET 9.0 | .NET 9.0 | 16.32 ns |  5.215 ns | 0.286 ns |         - |
    private string _letters = "01234567890abcdefghijklmnopqrstuvwxyZABCDEFGHIJKLMNOPQRSTUVWXYZ";

    [Benchmark]
    public void M1()
    {
        foreach (var c in _letters.AsSpan())
        {
            IsCapitalLetter(c);
        }
    }

    [Benchmark]
    public void M2()
    {
        foreach (var c in _letters.AsSpan())
        {
            IsCapitalLetter2(c);
        }
    }
    
    static bool IsCapitalLetter(char c) => c is >= 'A' and <= 'Z';
    static bool IsCapitalLetter2(char c) => (uint)(c - 'A') <= (uint)('Z' - 'A');    

Copy link
Collaborator

Choose a reason for hiding this comment

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

Odd that it behaves badly on NET 8 🤷🏻‍♂️ thanks for checking out

Copy link
Owner Author

Choose a reason for hiding this comment

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

If I remove the loop it's different ...

Copy link
Owner Author

Choose a reason for hiding this comment

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

| Method | Job               | Runtime  | Mean      | Error     | StdDev    | Median    | Allocated |
|------- |------------------ |--------- |----------:|----------:|----------:|----------:|----------:|
| M1     | ShortRun-.NET 8.0 | .NET 8.0 | 0.0943 ns | 2.9791 ns | 0.1633 ns | 0.0000 ns |         - |
| M2     | ShortRun-.NET 8.0 | .NET 8.0 | 0.0015 ns | 0.0466 ns | 0.0026 ns | 0.0000 ns |         - |
| M1     | ShortRun-.NET 9.0 | .NET 9.0 | 0.0053 ns | 0.1502 ns | 0.0082 ns | 0.0011 ns |         - |
| M2     | ShortRun-.NET 9.0 | .NET 9.0 | 0.0000 ns | 0.0000 ns | 0.0000 ns | 0.0000 ns |         - |


namespace Fluid.Utils;

public class HexUtilities
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe internal static?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I want to use it in the benchmark, and I can't get it to work because of public key (trust me I know how it works, but maybe I don't). I may just remove the benchmarks now that I have the result.

@sebastienros sebastienros merged commit 15b12f5 into main Nov 6, 2024
1 check passed
@sebastienros sebastienros deleted the sebros/improvements branch November 6, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants