[Mono-bugs] [Bug 354238] Future Optimization: Use Dictionary<string, int> for switch on string

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jan 17 09:14:51 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=354238

User juraj at hotfeet.ch added comment
https://bugzilla.novell.com/show_bug.cgi?id=354238#c4





--- Comment #4 from Juraj Skripsky <juraj at hotfeet.ch>  2008-01-17 07:14:50 MST ---
Created an attachment (id=190848)
 --> (https://bugzilla.novell.com/attachment.cgi?id=190848)
performance test case

I've done a little performance testing. The attached program compares the
performance of a switch-no-string with a switch-on-dictionary<string,int>. It 
takes one argument - the string to feed into the switch.

The switch-no-string case is tested twice - the first time with non-interned
string, the second with interned string.

Results on Mono:

[js at leonardo ~]$ mono switch.exe Hello
Switch:     415710
IsInterned: 426250

 -- string is interned from now on --

IsInterned: 328600
Switch:     317760
DictSwitch: 188090


[js at leonardo ~]$ mono switch.exe xxxxxxxx
Switch:     602920
IsInterned: 671700

 -- string is interned from now on --

IsInterned: 383080
Switch:     360620
DictSwitch: 151780


Interestingly "DictSwitch" is faster even when an interned string is feed into
"Switch" _and_ the interned string is the first match. That's why I included a
performance test for "String.IsInterned".
It turns out that a switch-on-string spents most of its time in
"String.IsInterned"!


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list