I check this PHP website benchmark for check switch statement
VS if else if statement
. And I see this result:
Is a there a difference between switch and if structures?. Call 1'000x
-
141 %
*if and elseif (using ==)*
Total time: 165 µsview code -
139 %
*if, elseif and else (using ==)*
Total time: 162 µsview code -
110 %
*if and elseif (using ===)*
Total time: 128 µsview code -
100 %
*if, elseif and else (using ===)*
Total time: 117 µsview code -
149 %
*switch / caseTotal*
time: 174 µsview code -
181 %
*switch / case / default*
Total time: 211 µsview code
In result i see if else if
is faster (+ **100 %** *if, elseif and else (using ===)* Total time: 117 µsview code
).
This benchmark is true and if, elseif and else (using ===)
is better and faster as switch statement?!