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

2004-10-17 Thread Michal Moskal
On Sat, Oct 16, 2004 at 07:11:49PM -0500, Marcus wrote: On Saturday 16 October 2004 7:20 am, Mike Welham wrote: Yes, and in fact, according to the CLI spec, it is difficult for the JIT to determine whether the a tail call can be used when the ldloca and ldarga instructions are involved.

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

2004-10-17 Thread Michal Moskal
On Sat, Oct 16, 2004 at 07:08:09PM -0500, Marcus wrote: On Saturday 16 October 2004 3:53 am, Michal Moskal wrote: No, I don't think that it's a completely a runtime issue. There are at least three fundamentally-different mechanisms for handling a switch statement, including hashing, binary

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

2004-10-17 Thread Paolo Molaro
On 10/17/04 Michal Moskal wrote: No, I don't think that it's a completely a runtime issue. There are at least three fundamentally-different mechanisms for handling a switch statement, including hashing, binary search, and a linear if/else. With CIL, there is the further complication of

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

2004-10-17 Thread Marcus
I will try to dig up the tests or to recreate them. You are probably correct that this is not a very large problem in practice. As I recall, I had to make the number of iterations quite large to see a substantial difference in time. On the other hand, I did this test because I have a program

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

2004-10-16 Thread Michal Moskal
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,

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

2004-10-16 Thread Mike Welham
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

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

2004-10-16 Thread Michal Moskal
On Sat, Oct 16, 2004 at 11:36:30AM +0200, Mike Welham wrote: 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

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

2004-10-16 Thread Mike Welham
... and if the high-level compiler can perform high-level optimizations it should. (When I say high-level optimizations I mean things like dead- code elimination or tail-call optimization.) I wouldn't say that the tail-call optimization is high level. You have the tail prefix in the

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

2004-10-16 Thread Marcus
On Saturday 16 October 2004 3:53 am, Michal Moskal wrote: No, I don't think that it's a completely a runtime issue. There are at least three fundamentally-different mechanisms for handling a switch statement, including hashing, binary search, and a linear if/else. With CIL, there is the

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

2004-10-16 Thread Marcus
On Saturday 16 October 2004 7:20 am, Mike Welham wrote: Yes, and in fact, according to the CLI spec, it is difficult for the JIT to determine whether the a tail call can be used when the ldloca and ldarga instructions are involved. I must admit that I do not quite understand how ldloca and

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

2004-10-15 Thread Stefan Matthias Aust
Fabien Meghazi schrieb: Method 3 :) left = or == 'l'; top = or == 't'; Both other methods disguise that you don't check the case that or isn't one of tlbr and that it could happen that you set neither left nor top. In general, I'd vote for the better communicating variant and/or the shorter

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

2004-10-15 Thread Fabien Meghazi
Fabien Meghazi schrieb: Method 3 :) left = or == 'l'; top = or == 't'; I can't use this because I iterate chars of the string in a foreach. If the string is two char long, the second iteration will cancel the effect of the first one. ___

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

2004-10-15 Thread Marcus
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.