[Mono-list] [Off-topic] "if else" or "switch" ?

Michal Moskal malekith@pld-linux.org
Sat, 16 Oct 2004 10:53:50 +0200


On Fri, Oct 15, 2004 at 05:39:01PM -0500, Marcus wrote:
> Performance will depend on both the C# compiler used and the runtime/JIT. I 
> have not tested four-way decisions, which is what you have, but I did test 
> three-way decisions not too long ago.
> 
> With Mono's C# compiler + mono runtime, if-statements were about 3 times 
> faster than switch. Interestingly, with Portable.NET's C# compiler, 
> if-statements and switch performed almost identically to each other (and to 
> Mono's C# if-statement version). So Mono's C# compiler is definitely not 
> producing the best code for the mono-runtime. 

I guess the entire idea behind the .NET is that the compiler don't have
to deal with choices like switch vs if -- the runtime is going to take
care of it. Using switch in the IL should be just a hint for the
runtime. So there is nothing to change in the mcs. The runtime is what
should be fixed, if anything.

Otherwise you're going to require other compilers to have
-optimize-mono, -optmize-ms-net, -optimize-pnet and
-optimize-some-other-bizzarre-yet-unknown-net-implemnetation
for maximum performance. And this isn't any good.

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: ::: Logic is a nice contrast to the Real World. :: UL++++$ C++ E--- a?