Post Reply 
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
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Checking conditions [IF ... THEN ... ELSE] performance - komame - 09-14-2015 06:24 PM



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