Skip to content

Instantly share code, notes, and snippets.

@marek-safar
Created January 13, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marek-safar/b26e2bfc9a60a2bd348b3f36d3cb8288 to your computer and use it in GitHub Desktop.
Save marek-safar/b26e2bfc9a60a2bd348b3f36d3cb8288 to your computer and use it in GitHub Desktop.
[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