Log in

View Full Version : What algorithm does AVS use to evaluate complex conditions?


fvisagie
22nd August 2009, 13:28
Hi All,

Say one has a complex conditional expression like:


result = expression0 || (expression1 && (expression2 || expression3)) ? expression4 : expression5


What sequence of steps would AVS follow if expression0 is true? At what point would it decide to go ahead and evaluate expression4 - would expression0-3 all get evaluated first, or would AVS bail out after determining that the top node is an OR and the left-hand expression is true?

I'm trying to establish if (other than through optimised logic) some speed efficiency can be obtained here by moving expressions that are really expensive to evaluate to a position where their evaluation will seldom be required?

Many thanks,
Francois

Gavino
22nd August 2009, 13:56
If expression0 is true, expressions 1-3 will not be evaluated at all.

Both || and && work like the corresponding operators in C/C++, only evaluating as far as they need to determine the final result.

Don't get too hung up on the efficiency of expressions, though. Most of Avisynth's time goes in processing pixels inside filters - in most cases the rest is negligable by comparison.

fvisagie
22nd August 2009, 15:16
You've earned yourself a mention in the script's credits :).