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

  1. -- PERFORMANCE MEASUREMENT : tasks entry call and return time
  2. --                           1 task 2 entries
  3. --                           one select statement
  4.  
  5. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ;
  6. package TASK_PACK_4 is
  7.   task T1 is
  8.     entry E1 ;
  9.     entry E2 ;
  10.   end T1 ;
  11. end TASK_PACK_4 ;
  12.  
  13. with TASK_PACK_4 ; use TASK_PACK_4 ;
  14. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ; -- control optimization
  15. with ITERATION ; -- obtain stable measurement
  16. with PIWG_IO ; -- output results
  17.  
  18. procedure T000004 is  -- main procedure to execute
  19.   CPU_TIME : DURATION ; -- CPU time for one feature execution
  20.   WALL_TIME : DURATION ; -- WALL time for one feature execution
  21.   CHECK_TIMES : constant := 100 ; -- inside loop count and check
  22.   ITERATION_COUNT : INTEGER ; -- set and varied by ITERATION package
  23.   STABLE : BOOLEAN ; -- true when measurement stable
  24.   CASE_COUNT : constant := 2 ;
  25.  
  26. begin
  27.  
  28.   ITERATION.START_CONTROL ;  -- dummy to bring in pages on some machines
  29.  
  30.   delay 0.5 ;  -- wait for stable enviornment on some machines
  31.  
  32.   ITERATION.INITIALIZE ( ITERATION_COUNT ) ;
  33.  
  34.   loop  -- until stable measurement, ITERATION_COUNT increases each time
  35.  
  36. --
  37. -- Control loop
  38. --
  39.     ITERATION.START_CONTROL ;
  40.     for J in 1 .. ITERATION_COUNT loop
  41.       GLOBAL := 0 ;
  42.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  43.         GLOBAL := GLOBAL + A_ONE ; 
  44.         REMOTE ;                   
  45.       end loop ;
  46.     end loop ;
  47.     ITERATION.STOP_CONTROL ( GLOBAL , CHECK_TIMES ) ;
  48.  
  49. --
  50. -- Test loop
  51. --
  52.     ITERATION.START_TEST ;
  53.     for J in 1 .. ITERATION_COUNT loop
  54.       GLOBAL := 0 ;
  55.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  56.         T1.E1 ; -- this has control global increment and call inside
  57.         T1.E2 ; -- this has control global increment and call inside
  58.       end loop ;
  59.     end loop ;
  60.     GLOBAL := GLOBAL / CASE_COUNT ;
  61.     ITERATION.STOP_TEST ( GLOBAL , CHECK_TIMES ) ;
  62.     ITERATION.TEST_STABLE ( ITERATION_COUNT , STABLE ) ;
  63.     exit when STABLE ;
  64.   end loop ;
  65. --
  66.   ITERATION.FEATURE_TIMES ( CPU_TIME , WALL_TIME ) ;
  67.   CPU_TIME := DURATION ( CPU_TIME / CASE_COUNT ) ;
  68.   WALL_TIME := DURATION ( WALL_TIME / CASE_COUNT ) ;
  69.  
  70. --
  71. -- Printout
  72. --
  73.   PIWG_IO.PIWG_OUTPUT ( "T000004" , "Tasking" ,
  74.                         CPU_TIME , WALL_TIME , ITERATION_COUNT ,
  75.      " Task entry call and return time measured" ,
  76.      " One tasks active, two entries, tasks in a package " ,
  77.      " using select statement " ) ;
  78.  
  79.   abort T1 ;
  80. end T000004 ;
  81.  
  82. package body TASK_PACK_4 is
  83.   task body T1 is
  84.   begin
  85.     loop
  86.       select
  87.         accept E1 do
  88.           GLOBAL := GLOBAL + A_ONE ;
  89.           REMOTE ;
  90.         end E1 ;
  91.       or
  92.         accept E2 do
  93.           GLOBAL := GLOBAL + A_ONE ;
  94.           REMOTE ;
  95.         end E2 ;
  96.       end select ;
  97.     end loop ;
  98.   end T1 ;
  99.  
  100. end TASK_PACK_4 ;
  101.