Forum Discussion

Paul_Michals_10's avatar
Icon for Nimbostratus rankNimbostratus
Jan 21, 2011

"if" verses "elseif" - performance question

Hello F5 DevCentral,



This comming Sunday I am to perform some minor maintenance on some of our existing F5 BIG-IP Virtual Servers when I will be modifing their iRules.



The question I have is: is it beter, from a performance perspective, to use "elseif" statements instead of sequential "if" statements give that there is no default "else" no matter what way the iRule is written?



Here is (with actual information removed) the proposed iRule:





if { [HTTP::uri] equals "/" } {






if { [matchclass [HTTP::uri] starts_with $::list1] } {


if { not [matchclass [IP::client_addr] equals $::internal_network] } {








if { [matchclass [HTTP::uri] starts_with $::list2] } {


if { not (([matchclass [IP::client_addr] equals $::allowed_addressses])


or ([matchclass [IP::client_addr] equals $::internal_network])) } {











Instead of the three outer "if"s would a set of "if", "elseif", "elseif" statements be faster?



Or are the diffferences insignificant?



Thanks in advance.

2 Replies

  • Here's a good article on optimizing iRules which covers if, elseif, and switch. I'd go with elseif here.





    Also, depending on your version, you might not need "$::" before your classes which would help performance.





    Let me know if you have any questions.




  • If those three checks are all mutually exclusive, I'd change the iRule so as few of checks are performed as possible. ie, if it's a request for / and you don't need to check for the IP addresses, either chain the checks in an if/elseif/elseif/else chain or use the return command to exit that iRule event in that iRule.





    Chris' suggestions are also good points to consider.