J
jehugaleahsa
Hello:
When developing data structures for C#, there is an obvious
performance hit when utilizing primitive types. For instance, a recent
hash table implementation I wrote works exceedingly fast on strings.
It can run through a million randomly generated strings in less than
half of a second (in most tests). The built-in dictionary class takes
close to 10 seconds. (Just trust my measurements; I don't want to
argue about the correctness of my tests)
However, switching over to a primitive type, such as int, double,
decimal, etc. will usually take significantly longer. The interesting
part is that C#'s built-in data structures seems to excel when
primitives are involved. The tables seems to turn, sort of speak.
The first thing that pops into mind is that there is some sort of
boxing occurring behind the scenes. If not that, it is some other
bottleneck I am overlooking.
Does anyone know why the built-in data structures are so primitive
friendly? Is there a way to utilize the technique(s) in my own data
structures?
Thanks for your time,
Travis
When developing data structures for C#, there is an obvious
performance hit when utilizing primitive types. For instance, a recent
hash table implementation I wrote works exceedingly fast on strings.
It can run through a million randomly generated strings in less than
half of a second (in most tests). The built-in dictionary class takes
close to 10 seconds. (Just trust my measurements; I don't want to
argue about the correctness of my tests)
However, switching over to a primitive type, such as int, double,
decimal, etc. will usually take significantly longer. The interesting
part is that C#'s built-in data structures seems to excel when
primitives are involved. The tables seems to turn, sort of speak.
The first thing that pops into mind is that there is some sort of
boxing occurring behind the scenes. If not that, it is some other
bottleneck I am overlooking.
Does anyone know why the built-in data structures are so primitive
friendly? Is there a way to utilize the technique(s) in my own data
structures?
Thanks for your time,
Travis