When Compiler Optimizations Hurt Performance
Recently I have been working on benchmarks comparing techniques for calculating UTF-8 sequence lengths.The method I described in Decoding UTF-8. Part IV: Determining Sequence Length - Counting Leading Bits uses hardware-assisted counting of leading zero bits:#include <bit>
int utf8_sequence_length(unsigned char lead_byte) {
switch (std::countl_one(lead_byte)) {
case 0: return 1;
case 2: return 2;
case 3: return 3;
case 4: return 4;
default: return 0; // invalid lead
}
}I was pretty disappointed ...
Read more at nemanjatrifunovic.substack.com