in reply to Re: What is the most efficient perl switch/case statement?
in thread What is the most efficient perl switch/case statement?

Programmer time is always worth more than CPU time.
That is a common myth, and understandably quite popular with programmers whose favourite programming language trades speed for programmer ease.

But in many case, it isn't true.

Some things just need to be fast, and the program speed dropping below a certain treshhold is not acceptable. In such cases, CPU time is worth more than programmer time.

Abigail

  • Comment on Re: What is the most efficient perl switch/case statement?

Replies are listed 'Best First'.
Re: Re: What is the most efficient perl switch/case statement?
by perrin (Chancellor) on Nov 21, 2003 at 17:31 UTC
    I realize you are making a general point, but it seems unlikely that choosing the slowest switch statement implementation in Perl will cause any aircraft to go down. People learning programming should be aware that micro-optimizations of this kind rarely have any significant payoff, and are typically only worth doing after using a profiler to see where the problems lie.
      I wasn't talking about the specific case of a switch in Perl. But the cliche made said that programmer time was always more important than CPU time. If duff meant a more specific case, he should have been more specific.

      Abigail

      #main system check loop big_airplane_002 while (1) { $status = Poll_status_on_hydraulic_systems($wingnumber); act_on_status($status); }
      What happens if Poll_status_on_hydraulic_systems uses a switch that runs 2x as slow as another viable choice? You lose polls on the equipment. Not saying that this would ever be done in perl (go go ADA) but you get the drift. The statement that programers time is more valuable than CPU is just silly. If you want to rationalize passing the buck by being a lazy programmer go for it. Its not for me.


      -Waswas
        Sorry, using an extreme case which involves something that no one would actually do in Perl anyway does not disprove the point that programmers should typically be more concerned about readability than speed when dealing with micro-optimizations like this one. Sure, you can find some case where a switch statement would make a difference, but it will be very rare. A reasonable approach to performance is to pick a good high-level architecture, write your program in a clear and readable way, profile it to find trouble spots, and fix them. Writing something that is hard to read from the beginning just because a confusing-looking switch statement ran a microsecond faster than the clearer one is not a good programming practice in any language.