Does having a lot of if statements degrade rendering speed of php?

前端 未结 6 1044
礼貌的吻别
礼貌的吻别 2021-01-02 04:12

I was wondering if complicated if/else structures in my PHP code could be a bad design decision. Does having a lot of if statements make PHP run slow, site load slower etc?<

6条回答
  •  清酒与你
    2021-01-02 04:58

    In a way..YES.
    I say this considering a Worst case scenario, in this case a very large model object with lots of conditions. Here, the code has to go through all conditional checking which eventually slows down the code.
    Conditional statements pose difficulty for parallelization and vectorization, and a long series of IF-THEN can also cause instruction cache misses and other effects. But if that's what makes the code clearest, then use it.

提交回复
热议问题