Forum Discussion
VictorC
Apr 05, 2012Nimbostratus
Performance question on 2 iRules
Hi all,
I have 2 different iRules I am using and they both do the same thing so that I can conserve IP addresses. I was wondering if there was any performance hit on a LTM running 10.2 if I...
dlg_23340
Apr 09, 2012Cirrus
There are plenty of examples from F5 about switch being faster than if/else. Here are a couple:
https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/108/iRules-Optimization-101--01--if-elseif-and-switch.aspx
An even more efficient manner of dealing with multiple if statements is to get rid of them all together! No, I don't mean remove the logic from your rule, I just mean use switch instead. The switch command is more efficient, in general, than using a string of if or even if/elseif statements. It's also flexible in the matching that you can do.
https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086424/Comparing-iRule-Control-Statements.aspx
Always think: "switch", "data group", and then "if/elseif" in that order.
If you think in this order, then in most cases you will be better off.
Use switch for < 100 comparisons.
Switches are fastest for fewer than 100 comparisons but if you are making changes to the list frequently, then a data group might be more manageable.
In general, I don't think twice before using a switch if it's more than just an if/else.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects