Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Optimize This! iRule Contest

JRahm
Community Manager
Community Manager
Hey there iRulers!

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" 
    } 
 }   
 
4 REPLIES 4

Nat_Thirasuttakorn
F5 Employee
F5 Employee
how about this one...

 

 

 

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)

JRahm
Community Manager
Community Manager
Excellent first entry! Thanks, natty76! Surely there are some other takers out there?

JRahm
Community Manager
Community Manager
C'mon, community! You have 24 hours... natty76 can't win by default!

JRahm
Community Manager
Community Manager
So...I guess I don't have much evaluation to do on this front...congrats natty76! I'll get a blog post up later today.