Quantcast
Channel: switch/case with string
Browsing latest articles
Browse All 13 View Live

switch/case with string

Thank you for the replies. It's good to know that switch on string can be used and it will be optimized! Discoveries like this can also give people confidence in the performance of C# and .NET in general.

View Article



switch/case with string

So it will optimize to do either a regular string comparison or a hashtable. The take-way being, prefer switch over if because it will optimize as your code evolves.

View Article

switch/case with string

For me it appears to use a hashtable if there are 10 or more cases.  This is with .NET 1.1. Code Snippetswitch (s){    case"str1":        Console.WriteLine("1");        break;    case"str2":...

View Article

switch/case with string

The post about hashes says that the hash isn't used until more than a few cases are used. This would make sense. 

View Article

Image may be NSFW.
Clik here to view.

switch/case with string

 Peter Ritchie wrote:I see nothing to do with hash tables when reflecting a switch statement.  It performs the same instructions as if would (ldloc, ldstr, call System.String_Equality), the only...

View Article


switch/case with string

I see nothing to do with hash tables when reflecting a switch statement.  It performs the same instructions as if would (ldloc, ldstr, call System.String : : op_Equality), the only difference is with a...

View Article

Image may be NSFW.
Clik here to view.

switch/case with string

The two previous posts contradict. One has a link that says hash tables are used and the other says that it is simple ifs. Please let's "hash" this out.

View Article

switch/case with string

Yes the C# compiler converts switches into a series of if statements.  With strings, it simply does a byte-wise comparison; it will not do a localized comparison.

View Article


switch/case with string

Check out this link for more info: http://benjaminm.net/PermaLink.aspx?guid=10071512-7fa5-43eb-9bbc-5c345d0e13f5. It seems that it does use some sort of hash table for the comparisons, although I seem...

View Article


switch/case with string

switch/case is using jump tables, but I do not exactly know on what it's based on the case of strings but I think it's using the direct representation of the strings. Maybe someone else knows some more...

View Article

switch/case with string

Thank you. What is the actual optimization mechanism (e.g. jump table based on hash of each string etc.)?

View Article

switch/case with string

If you step through your code you will see it is more efficient.  instead of forcing the compiler and your run time to compare your string values, the switch case jumps to the correct case... I think...

View Article

switch/case with string

Does C# optimize switch/case for strings in any way such that it is more efficient than a series of if-else(s) ? For example, the C++ compiler can use jump tables for switch/case with integers. (Note:...

View Article

Browsing latest articles
Browse All 13 View Live




Latest Images