[Mono-list] How many strings do I have?

Marcus mathpup@mylinuxisp.com
Thu, 7 Oct 2004 22:32:02 -0500


On the subject of switches on strings, I tested how mcs and the Mono runtime 
performed. Specifically, I tested the code that mcs produces for switches on 
strings versus nested if-statements for a three-way decision. The 
if-statement version was substantally faster (about 3-5 times, as I recall). 
The difference was due to how mcs handles switch statements. Using a 
different C# compiler, there was no difference between if-statements and 
switch under the Mono runtime.


On Thursday 07 October 2004 6:21 pm, Jonathan Gilbert wrote:

> 'switch' performs about the same with strings as it does with ints. How
> does it do this? It has to do with the fact that every separate object on
> the system has an object ID, which can be treated as an 'int'. This alone
> isn't enough, but coupled with the string intern pool, it is possible to
> come up with a "definitive" object ID that represents a given string.