home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / piwg / p000002.ada < prev    next >
Encoding:
Text File  |  1988-05-03  |  2.2 KB  |  81 lines

  1.  
  2. -- PERFORMANCE MEASUREMENT : procedure call and return time
  3. --                           no parameters
  4. --                           procedure local ( not inlinable)
  5.  
  6. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ; -- control optimization
  7. with ITERATION ; -- obtain stable measurement
  8. with PIWG_IO ; -- output results
  9.  
  10. procedure P000002 is  -- main procedure to execute
  11.  
  12.   CPU_TIME : DURATION ; -- CPU time for one feature execution
  13.   WALL_TIME : DURATION ; -- WALL time for one feature execution
  14.   CHECK_TIMES : constant := 100 ; -- inside loop count and check
  15.   ITERATION_COUNT : INTEGER ; -- set and varied by ITERATION package
  16.   STABLE : BOOLEAN ; -- true when measurement stable
  17.  
  18. --
  19.  
  20.   procedure PROC_0 is
  21.   begin
  22.     GLOBAL := GLOBAL + A_ONE ;
  23.     REMOTE ;
  24.   exception
  25.     when NUMERIC_ERROR => -- prevent inlining
  26.       PROC_0 ; -- can not be called if test working
  27.   end ;
  28.  
  29. begin
  30.  
  31.   ITERATION.START_CONTROL ;  -- dummy to bring in pages on some machines
  32.  
  33.   delay 5.0 ;  -- wait for stable enviornment on some machines
  34.  
  35.   ITERATION.INITIALIZE ( ITERATION_COUNT ) ;
  36.  
  37.   loop  -- until stable measurement, ITERATION_COUNT increases each time
  38.  
  39. --
  40. -- Control loop
  41. --
  42.     ITERATION.START_CONTROL ;
  43.     for J in 1 .. ITERATION_COUNT loop
  44.       GLOBAL := 0 ;
  45.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  46.         GLOBAL := GLOBAL + A_ONE ; 
  47.         REMOTE ;                   
  48.       end loop ;
  49.     end loop ;
  50.     ITERATION.STOP_CONTROL ( GLOBAL , CHECK_TIMES ) ;
  51.  
  52.  
  53. --
  54. -- Test loop
  55. --
  56.  
  57.     ITERATION.START_TEST ;
  58.     for J in 1 .. ITERATION_COUNT loop
  59.       GLOBAL := 0 ;
  60.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  61.         PROC_0 ; -- this has control global increment and call inside
  62.       end loop ;
  63.     end loop ;
  64.     ITERATION.STOP_TEST ( GLOBAL , CHECK_TIMES ) ;
  65.     ITERATION.TEST_STABLE ( ITERATION_COUNT , STABLE ) ;
  66.     exit when STABLE ;
  67.   end loop ;
  68. --
  69.   ITERATION.FEATURE_TIMES ( CPU_TIME , WALL_TIME ) ;
  70.  
  71. --
  72. -- Printout
  73. --
  74.   PIWG_IO.PIWG_OUTPUT ( "P000002", "Procedure",
  75.                         CPU_TIME , WALL_TIME , ITERATION_COUNT ,
  76.     " Procedure call and return time" ,
  77.     " Procedure is local, no parameters " ,
  78.     " when procedure is not inlinable" ) ;
  79.  
  80. end P000002 ;
  81.