Skip to content

Instantly share code, notes, and snippets.

@meziantou
Created January 21, 2019 14:46
Show Gist options
  • Save meziantou/c24d217567abd6669108e7d483b90599 to your computer and use it in GitHub Desktop.
Save meziantou/c24d217567abd6669108e7d483b90599 to your computer and use it in GitHub Desktop.
[Benchmark]
public string V1()
{
return string.Create(13, _id, (buffer, id) =>
{
var encode32CharsArray = _encode32CharsArray;
buffer[0] = encode32CharsArray[(id >> 60) & 31];
buffer[1] = encode32CharsArray[(id >> 55) & 31];
buffer[2] = encode32CharsArray[(id >> 50) & 31];
buffer[3] = encode32CharsArray[(id >> 45) & 31];
buffer[4] = encode32CharsArray[(id >> 40) & 31];
buffer[5] = encode32CharsArray[(id >> 35) & 31];
buffer[6] = encode32CharsArray[(id >> 30) & 31];
buffer[7] = encode32CharsArray[(id >> 25) & 31];
buffer[8] = encode32CharsArray[(id >> 20) & 31];
buffer[9] = encode32CharsArray[(id >> 15) & 31];
buffer[10] = encode32CharsArray[(id >> 10) & 31];
buffer[11] = encode32CharsArray[(id >> 5) & 31];
buffer[12] = encode32CharsArray[id & 31];
});
}
[Benchmark]
public string V2()
{
return string.Create(13, _id, (buffer, id) =>
{
var encode32CharsArray = _encode32CharsArray;
buffer[12] = encode32CharsArray[id & 31];
buffer[11] = encode32CharsArray[(id >> 5) & 31];
buffer[10] = encode32CharsArray[(id >> 10) & 31];
buffer[9] = encode32CharsArray[(id >> 15) & 31];
buffer[8] = encode32CharsArray[(id >> 20) & 31];
buffer[7] = encode32CharsArray[(id >> 25) & 31];
buffer[6] = encode32CharsArray[(id >> 30) & 31];
buffer[5] = encode32CharsArray[(id >> 35) & 31];
buffer[4] = encode32CharsArray[(id >> 40) & 31];
buffer[3] = encode32CharsArray[(id >> 45) & 31];
buffer[2] = encode32CharsArray[(id >> 50) & 31];
buffer[1] = encode32CharsArray[(id >> 55) & 31];
buffer[0] = encode32CharsArray[(id >> 60) & 31];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment