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

  1. -- PERFORMANCE MEASUREMENT :  Task entry call and return time measured
  2. --                            Two tasks active, one entry per task
  3. --                            tasks in a package
  4. --                            no select statement 
  5.  
  6. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ;
  7. package TASK_PACK_3 is
  8.   task T1 is
  9.     entry E1 ;
  10.   end T1 ;
  11.   task T2 is
  12.     entry E2 ;
  13.   end T2 ;
  14. end TASK_PACK_3 ;
  15.  
  16. with TASK_PACK_3 ; use TASK_PACK_3 ;
  17. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ; -- control optimization
  18. with ITERATION ; -- obtain stable measurement
  19. with PIWG_IO ; -- output results
  20.  
  21. procedure T000003 is  -- main procedure to execute
  22.   CPU_TIME : DURATION ; -- CPU time for one feature execution
  23.   WALL_TIME : DURATION ; -- WALL time for one feature execution
  24.   CHECK_TIMES : constant := 100 ; -- inside loop count and check
  25.   ITERATION_COUNT : INTEGER ; -- set and varied by ITERATION package
  26.   STABLE : BOOLEAN ; -- true when measurement stable
  27.   CASE_COUNT : constant := 2 ;
  28.  
  29. begin
  30.  
  31.   ITERATION.START_CONTROL ;  -- dummy to bring in pages on some machines
  32.  
  33.   delay 0.5 ;  -- 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.     ITERATION.START_TEST ;
  57.     for J in 1 .. ITERATION_COUNT loop
  58.       GLOBAL := 0 ;
  59.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  60.         T1.E1 ; -- this has control global increment and call inside
  61.         T2.E2 ; -- this has control global increment and call inside
  62.       end loop ;
  63.     end loop ;
  64.     GLOBAL := GLOBAL / CASE_COUNT ;
  65.     ITERATION.STOP_TEST ( GLOBAL , CHECK_TIMES ) ;
  66.     ITERATION.TEST_STABLE ( ITERATION_COUNT , STABLE ) ;
  67.     exit when STABLE ;
  68.   end loop ;
  69. --
  70.   ITERATION.FEATURE_TIMES ( CPU_TIME , WALL_TIME ) ;
  71.   CPU_TIME := DURATION ( CPU_TIME / CASE_COUNT ) ;
  72.   WALL_TIME := DURATION ( WALL_TIME / CASE_COUNT ) ;
  73. --
  74. -- Printout
  75. --
  76.   PIWG_IO.PIWG_OUTPUT ( "T000003" , "Tasking" ,
  77.                         CPU_TIME , WALL_TIME , ITERATION_COUNT ,
  78.      " Task entry call and return time measured" ,
  79.      " Two tasks active, one entry per task, tasks in a package " ,
  80.      " no select statement " ) ;
  81.   abort T1 ;
  82.   abort T2 ;
  83. end T000003 ;
  84.  
  85. package body TASK_PACK_3 is
  86.   task body T1 is
  87.   begin
  88.     loop
  89.       accept E1 do
  90.         GLOBAL := GLOBAL + A_ONE ;
  91.         REMOTE ;
  92.       end E1 ;
  93.     end loop ;
  94.   end T1 ;
  95.  
  96.   task body T2 is
  97.   begin
  98.     loop
  99.       accept E2 do
  100.         GLOBAL := GLOBAL + A_ONE ;
  101.         REMOTE ;
  102.       end E2 ;
  103.     end loop ;
  104.   end T2 ;
  105. end TASK_PACK_3 ;
  106.