Forum Discussion
smp_86112
Cirrostratus
Feb 02, 2010Efficiency of String Comparison
Which statement is more efficent in terms of processing?
[HTTP::uri] equals "/"
or
[HTTP::uri] == "/"
According to my interpretation of the official TCL doc, "equals" assumes the right side is already a string. On the other hand, "==" seems to assume the right side is a number. From the "==" description...
(i.e., numeric comparison if possible, exact string comparison otherwise).
So my conclusion is that "equals" is more efficent because the TCL engine does not have that extra decision to make.
I am just looking for a sanity check. I realize this is pretty meaningless in the context of a single rule, but we have this problem in many iRules - I'm looking for places to optimize. Thanks for your input.
4 Replies
Sort By
- hoolio
Cirrostratus
I'd agree--it's more efficient to use eq for string comparisons as TCL doesn't have to try to convert the value from a numeric to a string. You could confirm this using a loop of x comparisons using eq versus == using timing (Click here). - smp_86112
Cirrostratus
Dude, you're fast. And if you confirm, then it's gold. Thanks for taking the time to give your thoughts. - smp_86112
Cirrostratus
Not sure what's going on here - it seems that the stats only update when I update the iRule, not when I hit the applied VIP. I'm running 9.3.1, and I don't have time to dig into it at the moment - maybe there is some obvious incompatibility. - hoolio
Cirrostratus
Using time (Click here) in tclsh, it looks like eq is more efficient when the two operands aren't equal. Maybe == can do two checks: the first as numeric and the second as strings if the first check doesn't match. Just a guess...
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