- __builtin_popcount() and __builtin_popcountll() are great gcc builtins which perform bit population counts, useful for hamming distances (after the XOR operation, of course). [1]
- avoid scanf(), which is costly. My approach was to generate a header file with the char * words[] array, and also a int words_len[] with, you guessed it, the pre-computed lengths. Then go for the memcpy() route and you're in a much better position.
- speaking of memcpy, gcc provides one that should be optimal in most cases, but for really short words, it might be easiest to write your own. I came across a good article on it [2] but this is what I ended up using:
void
c_memcpy (char * dst, char * src, size_t len)
{
__builtin_prefetch(dst, 1, 3);
while (len--) {
*dst++ = *src++;
}
}
[1] http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Other-Builtins.h...[2] http://www.embedded.com/columns/technicalinsights/19205567