Forum Discussion
iRules command: Switch vs If
- Oct 06, 2020
Yes Morris. That's right.
If-statement with 3 conditions (and default).
if { $bla eq "one" } { # do something } elseif { $bla eq "two" } { # do something } elseif { $bla eq "three" } { # do something } else { # do something }
Switch-statement with 3 conditions (and default).
switch $bla { "one" { # do something } "two" { # do something } "three" { # do something } default { # do something } }
Don't forget to mark my answer as the best the help me for the contribution.
Regards,
Dario.
Hello Morris.
The same article states this:
"Generally, switch commands are faster than if statements due to additional expression evaluations that need to occur with if commands. Since the switch statements only works on a single comparison value, internal optimizations are able to be made in the evaluation process. This likely isn't going to be a big difference for one or two comparisons, but it is measurable when more are made."
It's because how the if statement is implemented at machine level.
Some reference:
http://www.blackwasp.co.uk/speedtestifelseswitch.aspx
Regards,
Dario.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com