08-May-2009
12:49
- last edited on
01-Jun-2023
08:23
by
JimmyPackets
I'm opening up a little optimization contest. For background on this iRule, check out Lori's blog (Click here) and my follow up (Click here)
I only optimized the variable reduction, I'm sure there are more options, however, so here's the challenge: the most efficient iRule in terms of avg CPU cycles wins. The winner will get some cool swag and a blog post featuring the winning iRule. Some guidelines:
1) The rule must work
2) The rule must provide like functionality
3) The rule must be provided in its entirety as a post in this thread no later than 5pm PDT 5/15/2009. No exceptions!
I will test all the rules on my lab box, which is currently running v10 hotfix 2. I'll announce the winner the following week.
Sound good? Can't wait for your entries...Jason
Here's Lori's original iRule:
when HTTP_REQUEST timing on {
set uri [HTTP::uri]
if {$uri starts_with "/roll"} {
set v1 [URI::query [HTTP::uri] "num"]
set v2 [URI::query [HTTP::uri] "d"]
set total 0
for {set i 0} { $i < $v1} {incr i} {
set dieroll [expr {int(rand()*$v2) + 1}]
set result1 [expr {round($dieroll)}]
set total [expr {$total + $result1}]
}
HTTP::respond 200 content "$v1 d $v2 = $total"
}
}
08-May-2009 18:12
when RULE_INIT {
set static::max 10
set static::f(0) { $num }
set i 1
while { $i < $static::max } {
eval "set static::f($i) { $static::f([expr $i - 1]) + int(rand() * \$d) }"
incr i
}
}
when HTTP_REQUEST timing on {
if { [HTTP::uri] starts_with "/roll"} {
set num [URI::query [HTTP::uri] "num"]
set d [URI::query [HTTP::uri] "d"]
HTTP::respond 200 content "$num d $d = [expr $static::f($num)]"
}
}
* I guess we can remove round() function since its input is arealdy integer.. (correct me if I am wrong)
12-May-2009 07:45
14-May-2009 12:42
19-May-2009 09:14