How much µ seconds?
120 Nanoseconds each iteration !
That's quite logical; using a string-case is almost exactly as doing the long series of nested IFs, while the hash (or any other ordinal) CASE is optimized through jumptables and what-not.
The hash case also becomes a series of nested IFs. But an integer comparison is faster than a string comparison
Note, though, that AFAICS your test doesn't capture the time taken to calculate the hash from the strings; it might or might not be significant, depending on the hash method and the kind (and length) of the strings.
It tests both.
But that is on purpose, since I use it for HTML and calculate the hash for all HTML elements when loading the file
Nevertheless that is why I have a hunch that that a trie would perform better than a hash
It also needs to support ranges.
Is there really a need for ranges?
But hey, guess what, if you want you can provide patches to improve it.
I already wrote a bye-coded trie for my Internet Tools. You could copy it