in reply to What is the most efficient perl switch/case statement?
So, since there are so many ways to code switch/case constructs in perl (half a dozen in the camel book alone), which way is the most efficient as far as execution speed goes?
It seems to me that you should be more interested in which method is easiest to understand. Programmer time is always worth more than CPU time. I usually use an if/elsif/else ladder since most programmers can figure out what that's doing even if they're weak on perl skills.
But if you're really interested in which is faster, develop a large data set that would cause each branch to succeed individually or all fail, and then apply that data set to a particular switch construct. Mostly though, I think you'll be benchmarking your ability to implement the switch (And the test) rather than the particular switch-style.
Update: Fine. For the pedants out there: Programmer time is almost always worth more than CPU time. Of course there are situations where execution speed is critical. In my experience though, if you're programming in perl, execution speed isn't your top concern. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is the most efficient perl switch/case statement?
by Abigail-II (Bishop) on Nov 21, 2003 at 16:20 UTC | |
by perrin (Chancellor) on Nov 21, 2003 at 17:31 UTC | |
by Abigail-II (Bishop) on Nov 21, 2003 at 19:16 UTC | |
by waswas-fng (Curate) on Nov 21, 2003 at 18:10 UTC | |
by perrin (Chancellor) on Nov 21, 2003 at 18:43 UTC | |
by waswas-fng (Curate) on Nov 21, 2003 at 20:28 UTC | |
|