in reply to Re: fall through switch/case in perl
in thread fall through switch/case in perl

Actually, this is just a standard switch statement,-- not Duff's device.

On the clarity argument, it's very much in the eye of the beholder whether your if cascade (or the and cascade) is clearer than the computed-goto version?

For completeness, the computed goto version works out an average of over 60% faster than either of the cascade versions, which is rather more than a few dozen clock cycles.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^3: fall through switch/case in perl
by Aristotle (Chancellor) on Sep 07, 2004 at 03:21 UTC

    That's because it doesn't test and retest conditions like the cascades do, it just computes a goto target.

    Makeshifts last the longest.

      I know that! And that's why it's a better conversion of the c switch statement.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon