3 ms·
And don't forget that you still have a switch statement with multiple branching operations that pick out this code among the various options of hash table size!
by PeterisP 10y ago
And don't forget that you still have a switch statement with multiple branching operations that pick out this code among the various options of hash table size!
This is something where function pointers / overloading would likely have even better performance than direct switching - when the hash table size changes, switch out the function from modulo_by_511 to modulo_by_711.
- minimax 10y agoAny reasonably good optimizing compiler will implement that switch statement as a jump table so it's really just one conditional branch even though it doesn't look like it.
- rurban 10y agoBut this compiler will add unneeded bounds checking (3-10% perf. hit). A computed goto table would fix that. (on modern compilers). Anyway, Lemire's fastrange modulo solved that problem better. https://github.com/lemire/fastrange https://github.com/lemire/fastrange There's no need for a slow modulo.