4 Replies Latest reply on Mar 22, 2011 12:54 PM by fitch

# Does this make a difference?  Which way is better?

### Title

Does this make a difference?  Which way is better?

### Post

Hi Guys,

I have a script that needs to evaluate a statement containing about 20 conditionals.  Which of these 2 methods is better?  (I am going to shorten my example just a bit)

Assume for this example their are 4 global variables containing a number:

\$\$w, \$\$x, \$\$y, and \$\$z and we only want to preform doSomething if w=500, x=200, y=100 and z=50.

I could do a script like this:

Example 1

Set Variable[\$flag; Value:True]

If [\$\$w <> 500 or \$\$x <> 200 or \$\$y <> 100 or \$\$z <> 50]

Set Variable[\$flag; Value:False]

End If

If [\$flag = True]

doSomething

End If

or I could do something like this:

Example 2

If [\$\$w = 500]

If [\$\$x = 200]

If [\$\$y = 100]

If [\$\$z = 50]

doSomething

End If

End If

End If

End If

Both examples should evaluate the same.  Imaging I had 20 - 25 values of compare which way would you use?  Will one of the two

perform faster?

Chris

• ###### 1. Re: Does this make a difference?  Which way is better?

You could also use:

If [\$\$w = 500 and \$\$x = 200 and \$\$y = 100 and \$\$z = 50]

Do something

end If

But I don't know if one will execute more quickly than another. I'd think that combining the evaluation in a single expression will execute more quickly, but I could easily be wrong here.

You could always run some tests with your own data or in a sample file and see what results you get...

• ###### 2. Re: Does this make a difference?  Which way is better?

I figured I would have to buid a test to find out the answer.  (I am all ready working on it.)  I was kind of hoping someone here would have all ready run into this and know the answer up front.  I will post the answer here for the curious.

Chris

• ###### 3. Re: Does this make a difference?  Which way is better?

I am a little supprised with how drastic the results are.  I wrote a test case for this that timed it either way over 10000 iterations of a loop.  Creating a long if statement with multiple and and ors is over twice as fast as multiple script steps.  4 seconds vs 8 seconds.

Chris

• ###### 4. Re: Does this make a difference?  Which way is better?

It seems to me I read some discussion long ago about the calculation engine being faster than the scripting engine, which would coincide with your results.