Max FunctionA task frequently undertaken in programming is determining the highest value. One approach is to compare values using IF statements, as illustrated in this simple example. This program prints the highest value of the three variables, which would be 19. var i,j,k: integer; The CompilerStats statement reports the resources used by this program. The compiled program used 5 labels, 6 constants, 27 stack items, and 54 instructions (tokens). ARRAY MAX USED It is not the purpose of this tutorial to dig into the inner workings of the ESPL compiler. Rather, I am interested in the efficiency gained by a 2nd approach. Instead of finding the highest value using IF statements, the MAX function can be used. The MAX function returns the highest value from among its parameters. MAX may have up to 100 parameters. The task of the 1st example can be coded more efficiently this way. var i,j,k: integer; This time the program used 1 label, 5 constants, 16 stack items, and 32 instructions. The statistic we are most interested in is the number of instructions because that affects execution speed. ARRAY MAX USED |