Re: New switch/case idea
- Posted by jimcbrown (admin) Apr 10, 2009
- 1632 views
Sorry, doesn't count. Your test program has a for loop for the operation[i] = routine_id(opName[i]), but then it stupidly uses the exact same for loop with the switch inside.
Yes, but that one is switching procedure from compile.e, it is not my procedure.
Ok, I didn't notice. It was from an old version of compile.e (as it had the wrong syntax), but that was easy enough to deal with.
I also had to add a couple of routines to handle some missing routines, again no big deal.
Functionality-wise, you are right. This is the InitBackend() from compile.e (oddly, the InitBackend() from execute.e matches your other routine).
Both procedures give strongly equal output.
But my procedure is 50% faster, no?
However, if we change init_opcodes() to use switch on integers instead of on strings, we go from 14.4 to 7.85
So much for the speed advantage.
In any case, InitBackend() is not a speed critical routine, so making the code easy to read and change and debug is more important. The switch statement method is better for this purpose than the parallel arrays version, for the reason I already stated.