Performance - dicasPerformance - dicas

Top  Previous  Next

There are some tips how to speed up your programs: 

-----------------------------------------------------------------------------

1. Instead of:                     Use: 

  A := A + 1;                      Inc(A); 

  A := A - 1;                      Dec(A); 

  S := S + [A];                    Include(S, A); 

  S := S - [A];                    Exclude(S, A); 

  A := B * 2;                      A := B shl 1

  A := B div 2;                    A := B shr 1

  if (A >= 1and (A <= 9) then    if (A in 1..9) then 

-----------------------------------------------------------------------------

2. Use Integer instead of the others integer types because it is faster. 

   Use ShortInt only in arrays to save up memory. 

 

   And don't assume that floating point operations are slower than 

   the integer operations. 

 

   The contemporary FPUs can perform most of the operation for a single tact. 

-----------------------------------------------------------------------------

3. The compiler optimizer does its work fine but you can help it to 

   make it better. Copy a global variable to a 

   local so it can be copied in a register. 

 

   When calling a procedure or a function if possible try using only 3 

   simple parameters (2 for methods). 

   This way they will be passed to the procedure in registers 

   not in the system stack. 

-----------------------------------------------------------------------------

4. When writing "if (cond1) or (cond2) then", cond1 must be the condition 

   which becomes true more often or which is calculated faster. 

   If the first condition is true the second is not calculated. 

   Its almost the same in the case of "if (cond1) and (cond2) then" but this 

   time cond1 must be more often false (if so cond2 is not calculated).