Forum Discussion

JRahm's avatar
JRahm
Icon for Admin rankAdmin
May 08, 2009

Optimize This! iRule Contest

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

  • 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)
  • Excellent first entry! Thanks, natty76! Surely there are some other takers out there?
  • C'mon, community! You have 24 hours... natty76 can't win by default!
  • 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.