Checking conditions [IF ... THEN ... ELSE] performance
09-14-2015, 06:24 PM (This post was last modified: 09-14-2015 08:17 PM by komame.)
Post: #1
 komame Member Posts: 50 Joined: Aug 2015
Checking conditions [IF ... THEN ... ELSE] performance
Hi,

I wonder if the checking conditions in HPPL are working properly.
It looks that all of the AND conditions are always executed even if first one returns false.
The same problem is for the OR conditions when the the first return true.

For example, if the expression is composed of three conditions and each of them is false then there is no need to check each of them. This is how languages C, C#, Java and other works.

HPPL seems to check every time all the conditions which may greatly slow down the program execution.

I did a little test for three conditions that each of them return false:

Example:
Code:
EXPORT TESTCONDITIONS() BEGIN   LOCAL a,b,x,t;   [[1,2,3],[4,5,6],[7,8,9]]▶a;   PRINT(); //first test   0▶b;   TICKS▶t;   FOR x FROM 1 TO 10000 DO     IF a[3,2]=7 AND a[1,1]=4 AND a[3,3]=8 THEN       b+1▶b;     END;   END;   PRINT(TICKS-t); //second test   0▶b;   TICKS▶t;   FOR x FROM 1 TO 10000 DO     IF a[3,2]=7 THEN       IF a[1,1]=4 THEN         IF a[3,3]=8 THEN           b+1▶b;         END;       END;     END;   END;   PRINT(TICKS-t); END;

When the program finishes there will be two measurements of time.
First is about 750 [ms] and the second id 360 [ms].
The first is test of 10000 times of three conditions using AND, the second is the same but use of implantation conditions. In the second case the program ran twice as fast.

The conditions can be very complex, eg. a complex function which returns true or false. Then check each of them is a large loss of performance.

I think HPPL would work like in other languages which would greatly accelerate programs execution.
 « Next Oldest | Next Newest »

 Messages In This Thread Checking conditions [IF ... THEN ... ELSE] performance - komame - 09-14-2015 06:24 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - Joe Horn - 09-14-2015, 07:21 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - Tim Wessman - 09-14-2015, 07:36 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - komame - 09-14-2015, 09:01 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - primer - 09-14-2015, 09:24 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - Joe Horn - 09-15-2015, 05:04 AM RE: Checking conditions [IF ... THEN ... ELSE] performance - roadrunner - 09-14-2015, 10:06 PM RE: Checking conditions [IF ... THEN ... ELSE] performance - cyrille de brébisson - 09-15-2015, 05:25 AM RE: Checking conditions [IF ... THEN ... ELSE] performance - StephenG1CMZ - 09-15-2015, 09:42 AM

User(s) browsing this thread: 1 Guest(s)