-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Conversation
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be difference with the IsInRange
trick: https://sharplab.io/#v2:C4LglgNgNAJiDUAfAAgZgATIEzoMLoG8BYAKHXOQEYA2dAIwHsGJ0BJAZ1wEMAHMYLhAAyAU2DARAJwAUAYwAWXSelkBKdAF4AfCvRh26LRvQByAIIn0XAHYx0AHmMmAWiYDcpcphr0mLDtx8AsJiEpJYcorKapo60gCuYNbAqnLoALSmFuqO6AlJKdIulpnmJqoeJAC+QA=
Edit: removed unnecessary parameters from earlier version.
There was a problem hiding this comment.
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');
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ...
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe internal static
?
There was a problem hiding this comment.
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.
No description provided.