Are lookup tables for case-converting, ASCII only characters [0,127] faster than arithmetic operation?

11 hours ago 1
ARTICLE AD BOX

Imagine I have a long string 10 kb characters, filled with random ASCII characters.
And I want to lowercase them. One way i could do that is by using a simple operation like:

inline char lowercase(char c) { return c + 0x20 * (c >= 'A' && c <= 'Z'); }

Another way would be to create a lookup table like:

constexpr unsigned char table[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, ..... }

Given some std::string src = "some_random_characters";

This would require memory accesses like table[src[i]] and the other would require lowercase(src[i]) which do you expect to be faster?

What's a good strategy to implement lookup table for fast accesses?

Read Entire Article