Created
January 13, 2020 16:26
-
-
Save marek-safar/b26e2bfc9a60a2bd348b3f36d3cb8288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Benchmark] | |
public char Test_Condition () | |
{ | |
return Convert_Condition (14); | |
} | |
[Benchmark] | |
public char Test_String () | |
{ | |
return Convert_String (14); | |
} | |
[Benchmark] | |
public char Test_ROS () | |
{ | |
return Convert_ROS (14); | |
} | |
public static char Convert_Condition (int value) | |
{ | |
value &= 0xF; | |
return (char)(value > 9 ? value - 10 + 'A' : value + '0'); | |
} | |
public static char Convert_String (int value) | |
{ | |
return "0123456789ABCDEF"[value & 0xF]; | |
} | |
internal static ReadOnlySpan<byte> ros => new byte[16] | |
{ | |
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', | |
(byte)'8', (byte)'9', (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F' | |
}; | |
public static char Convert_ROS (int value) | |
{ | |
return (char)ros[value & 0xF]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment