More rules or Otherwise?

irongirong Member Posts: 41
edited November -1 in Working with GS (Mac)
Hello Guys,

performance side, is it better to have :

Rule 1 : When X = 3 Then DO that
Rule 2 : When X = 4 Then Do that
Rule 3 : When X = 5 Then Do that

or this :

Rule 1 : When X =3 Then Do that
Otherwise When X = 4 Then Do that
Otherwise etc.

So One complicated Rule against, X rules? What do you think is the best for perf? thanks guys

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    i think the complicated rule is better for performance, because it;s not constantly checking multiple rules if they are true, but someone else could chime in whos experimented with it.
  • MotherHooseMotherHoose Member Posts: 2,456
    also:

    mainRule with condition: when
    Attribute n > 1 (here the computer reads/stores n value)

    ---Rule when x = 3 do this (here the computer compares 3 to 0)
    (if = …returns 1…true… initiates event...and stops reading mainRule)
    (if ≠ …returns 0…false… continues reading)

    ---Rule when x = 4 do this (here the computer compares 4 to 0)
    (if = ...returns 1…true… initiates event..and stops reading mainRule)
    (if ≠ ...returns 0…false… continues reading)

    ---Rule when x = 5 do that (here the computer compares 5 to 0)
    (if = ...returns 1…true… initiates event..and stops reading mainRule)
    (if ≠ ...returns 0…false…continues reading)

    Otherwise: (if above comparisons return 0 ...false)
    ---do something else (initiate event)

    as the computer does this in nanoseconds…
    all this doesn’t too much matter … but we all want things to happen instantaneously…
    so we should strive to write sequential code efficiently…thus we should nest rules that concern a particular state/attribute.

    MH
  • irongirong Member Posts: 41
    Wow thanks for the answers, very helpful!
Sign In or Register to comment.