Skip to content

Instantly share code, notes, and snippets.

@jzebedee
Last active August 29, 2015 14:04
Show Gist options
  • Save jzebedee/f5f13c68c022643cc11a to your computer and use it in GitHub Desktop.
Save jzebedee/f5f13c68c022643cc11a to your computer and use it in GitHub Desktop.
WriteInt64 benchmark winners
//winner x64
private static void WriteInt64E(long y, byte[] buf, int offset)
{
if (y < 0)
{
y = -y;
buf[offset] = (byte)y;
buf[offset + 1] = (byte)(y >>= 8);
buf[offset + 2] = (byte)(y >>= 8);
buf[offset + 3] = (byte)(y >>= 8);
buf[offset + 4] = (byte)(y >>= 8);
buf[offset + 5] = (byte)(y >>= 8);
buf[offset + 6] = (byte)(y >>= 8);
buf[offset + 7] = (byte)((y >> 8) | 0x80);
}
else
{
buf[offset] = (byte)y;
buf[offset + 1] = (byte)(y >>= 8);
buf[offset + 2] = (byte)(y >>= 8);
buf[offset + 3] = (byte)(y >>= 8);
buf[offset + 4] = (byte)(y >>= 8);
buf[offset + 5] = (byte)(y >>= 8);
buf[offset + 6] = (byte)(y >>= 8);
buf[offset + 7] = (byte)(y >> 8);
}
}
//winner x86
private static void WriteInt64F(long value, byte[] buf, int offset)
{
long y = value < 0 ? -value : value;
buf[offset] = (byte)y;
buf[offset + 1] = (byte)(y >>= 8);
buf[offset + 2] = (byte)(y >>= 8);
buf[offset + 3] = (byte)(y >>= 8);
buf[offset + 4] = (byte)(y >>= 8);
buf[offset + 5] = (byte)(y >>= 8);
buf[offset + 6] = (byte)(y >>= 8);
buf[offset + 7] = (byte)(y >>= 8);
if (value < 0)
buf[offset + 7] |= 0x80;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment