On Tuesday, September 28, 2010 15:46:01 Iain Buclaw wrote: > Out of curiousity, I thought I might give a good stress test a try. > > Specs of my machine: > > Samsung N110, 2.1GHz Intel Atom, 2GB Memory. > > Code looks like this: It's a switch statement with 20,000 cases.
The real question though isn't worst case performance but rather average performance. 20,000 cases is totally unrealistic. 100 cases would be rare. 10 is probably the most that you get in most code, though obviously there are cases where you'd get quite a few more. If dmd produced code that was very efficient for the average case but horrible for the worst case, I think that that would be fare better than producing code that was mediocre for the average case and good for the worst case. Of course, if it was determined that a particular algorithm worked well in smaller cases and another in larger cases, then you could just have the compiler use the algorithm that works best for the number of case statements that you have, but regardless, while how fast switch statements are with an insane numbers of case statements may be interested, it's nowhere near as relevant as how fast they are with a relatively small number. Whether there's any relation between the speed with a small number of case statements and the speed with a large number is something that would have to be verified before 20,000 cases becomes particularly relevant, much as it would be theoretically nice if having 20,000 case statements were efficient. - Jonathan M Davis
