if else VS switch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    #1

    if else VS switch

    Hi,

    The behavior between if else and switch is not different in PHP.
    However is there difference for the performance (I know in C it's
    different) while interpreting the script?

    Thanks in advance

    Don
  • Good Man

    #2
    Re: if else VS switch

    Don <NOSPAMdon.h@fr ee.fr> wrote in news:44561ee5$0 $14027
    $626a54ce@news. free.fr:
    [color=blue]
    > Hi,
    >
    > The behavior between if else and switch is not different in PHP.
    > However is there difference for the performance (I know in C it's
    > different) while interpreting the script?
    >
    > Thanks in advance[/color]

    if i recall correctly, one of the bugfixes/improvements to the
    latest/greatest PHP version was improving the speed of switch statements...
    so I assume they are as fast as if/else at least right now...

    obviously the real benefit of using 'switch' is that its great for going
    through many possible conditions, and results in far more readable code.

    Comment

    • Schraalhans Keukenmeester

      #3
      Re: if else VS switch

      Don wrote:[color=blue]
      > Hi,
      >
      > The behavior between if else and switch is not different in PHP.
      > However is there difference for the performance (I know in C it's
      > different) while interpreting the script?
      >
      > Thanks in advance
      >
      > Don[/color]
      Why don't you test it ? using microtime() this should be a piece of cake.

      Which one should be faster in C according to your data?
      Sh.

      --
      Sigh. I like to think it's just the Linux people who want to be on
      the "leading edge" so bad they walk right off the precipice.
      (Craig E. Groeschel)

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: if else VS switch

        Don wrote:[color=blue]
        > Hi,
        >
        > The behavior between if else and switch is not different in PHP.
        > However is there difference for the performance (I know in C it's
        > different) while interpreting the script?[/color]

        IIRC, switch is based on look up tables and might be faster.

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

        Comment

        Working...