Date: Fri, 9 Feb 2001 17:44:48 -0000
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject: Re: Is Boolean logic faster?
Content-Type: text/plain; format=flowed
They compile into different things, but produce the same result. However, #2
does not involve multiplication. So it will be about 50% faster if the first
condition is true (so that both will have to be evaluated). If the first
condition is false, #2 will be more than 2 times faster. Finally, if you do
not care if TEST is zero or missing when it is not 1, this will be *still*
if num > 0 then if color='B' then test=1;
So it is not really the question about Boolean logic being faster, but
rather about the number of operations the computer has to perform and their
cost. A valid question about boolean vs non-boolean logic *could* be: Which
expression does SAS evaluate faster: <if num=1> or <if num> ? If the actual
condition is true, then the answer is <if num=1>, because in this case SAS
only has to compare NUM with 1, i.e. perform at most one comparison, while
in order to evaluate <if num> SAS must ensure that NUM is greater than .Z
and not 0, i.e. perform at most 2 comparisons.
Paul M. Dorfman
>From: Nigel Tufnel <dousk8@HOTMAIL.COM>
>Is Boolean logic faster? Does it matter?
>Which is faster
> test = ((num > 0)*(color='B'));
> if num > 0 and color = 'B' then test=1; else test=0;
>Do both statements compile into the same thing?
>Get your FREE download of MSN Explorer at http://explorer.msn.com
Get your FREE download of MSN Explorer at http://explorer.msn.com