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

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