DaTurk said:
That's basically my question, if I use a generic dictionary, and key
it off a 32 bit int, rather then a string ... will there be any speed
difference when I search? Even if there is a benefit, however
negligible, I'd still like to know about it.
The only way to answer the question with certainty is for _you_ to
measure the performance in both scenarios, in the context of your own code.
As a general rule, I'd guess that int could be much faster than a string
in a pure benchmark. After all, an array of ints is a single
allocation, whereas every new string you have to allocate and add as a
key to your dictionary requires a new object. And calculating the hash
code for a 32-bit int is much faster than for a string, since it's just
the int value itself.
But: strings used as indices for your collection may be strings that
have to be allocated anyway, the hash code may be cached and/or
precalculated, and if the int isn't a natural connection to your
underlying data, there could be additional overhead associated with
using an int that isn't readily apparent in a pure benchmark.
There's no way for anyone to be able to know whether _in your specific
case_ which would be faster, because there are too many things that can
affect the overall performance. If it's that important (and frankly, I
doubt it is) you'll just have to implement it yourself and measure each
way to find out which is faster.
Pete