Ada 95 Quality and Style Guide Chapter 10

Chapter 10: Improving Performance - TOC - 10.5 ALGORITHMS

10.5.1 Mod and rem Operators

guideline

  • Use incremental schemes instead of mod and rem when measured performance indicates.

  • example

       -- Using mod
       for I in 0 .. N loop
          Update (Arr (I mod Modulus));
       end loop;
    
       -- Avoiding mod
       J := 0;
       for I in 0 .. N loop
          Update (Arr (J));
          J := J + 1;
          if J = Modulus then
             J := 0;
          end if;
       end loop;
    
    

    rationale

    Determine the impact of using the mod and rem operators. One of the above styles may be significantly more efficient than the other.


    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC TOC
    Appendix References Bibliography