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

  1. -- PERFORMANCE MEASUREMENT : task creation and termination time
  2. --                           1 task no entry
  3. --                           task type in package, no select
  4.  
  5. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ;
  6. package CREATE_PACK_1 is
  7.   task type T1 is
  8.   end T1 ;
  9.   procedure P1 ; -- will create task, run task, and terminate task
  10. end CREATE_PACK_1 ;
  11.  
  12. with CREATE_PACK_1 ; use CREATE_PACK_1 ;
  13. with REMOTE_GLOBAL ; use REMOTE_GLOBAL ; -- control optimization
  14. with ITERATION ; -- obtain stable measurement
  15. with PIWG_IO ; -- output results
  16.  
  17. procedure C000001 is  -- main procedure to execute
  18.  
  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.  
  25.  
  26. begin
  27.  
  28.   ITERATION.START_CONTROL ;  -- dummy to bring in pages on some machines
  29.  
  30.   delay 5.0 ;  -- 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. -- establish task create and terminate time
  53.  
  54.     ITERATION.START_TEST ;
  55.     for J in 1 .. ITERATION_COUNT loop
  56.       GLOBAL := 0 ;
  57.       for INSIDE_LOOP in 1 .. CHECK_TIMES loop
  58.         P1 ; -- this has task that has global increment and call inside
  59.       end loop ;
  60.     end loop ;
  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.  
  68. --
  69. -- Printout
  70. --
  71.   PIWG_IO.PIWG_OUTPUT ( "C000001" , "Tasking" ,
  72.                         CPU_TIME , WALL_TIME , ITERATION_COUNT ,
  73.     " Task create and terminate measurement " ,
  74.     " with one task, no entries, when task is in a procedure" ,
  75.     " using a task type in a package, no select statement, no loop, " ) ;
  76.  
  77. end C000001 ;
  78.  
  79. package body CREATE_PACK_1 is
  80.   task body T1 is
  81.   begin
  82.     GLOBAL := GLOBAL + A_ONE ;
  83.     REMOTE ;
  84.   end T1 ;
  85.  
  86.   procedure P1 is
  87.     T : T1 ; -- this creates the task, runs task to completion and terminates
  88.   begin
  89.     null ;
  90.   end P1 ;
  91.  
  92. end CREATE_PACK_1 ;
  93.