Forum Discussion
simple if statements optimized to switch statements ?
I think you can pull two rules of thumb from the above:
-
It's always better to use fewer variables if possible. Variables take up additional memory. So the following:
set path_lower [string tolower [HTTP::path]] if { ( path_lower eq "somepage.html" ) || ( path_lower eq "anotherpage.html" ) } { pool mypool-01 }would be better like this:
if { ( [string tolower [HTTP::path]] eq "somepage.html" ) || ( [string tolower [HTTP::path]] eq "anotherpage.html" ) } { pool mypool-01 } -
A switch is generally more efficient than an if, but the difference would likely be negligible for a small set of evaluations. You'll also find that an if is usually more flexible than a switch. A switch can, at the most, evaluate wildcards with a -glob option, while an if can evaluate regular expressions and beyond. All of that said, I would still probably opt for a switch, when possible, when I have at least two or more evaluations to perform.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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