home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / timer.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  2.3 KB  |  78 lines

  1.                                      -- Chapter 24 - Program 1
  2. with Text_IO; use Text_IO;
  3. with Calendar; use Calendar;
  4.  
  5. procedure Timer is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.    package Fix_IO is new Text_IO.Fixed_IO(DAY_DURATION);
  10.    use Fix_IO;
  11.  
  12.    Year,Month,Day : INTEGER;
  13.    Start,Seconds  : DAY_DURATION;
  14.    Time_And_Date  : TIME;
  15.  
  16. begin
  17.  
  18.    Put_Line("Begin 3.14 second delay");
  19.    delay 3.14;
  20.    Put_Line("End of 3.14 second delay");
  21.  
  22.    Time_And_Date := Clock;
  23.    Split(Time_And_Date,Year,Month,Day,Start);  -- get starting time
  24.  
  25.    for Index in 1..9 loop
  26.       Put("The date and time are now");
  27.       Time_And_Date := Clock;
  28.       Split(Time_And_Date,Year,Month,Day,Seconds);
  29.       Put(Month,3);
  30.       delay 0.2;
  31.       Put(Day,3);
  32.       delay 0.1;
  33.       Put(Year,5);
  34.       delay 0.1;
  35.       Put(Seconds - Start,8,3,0);
  36.       New_Line;
  37.       delay 0.6;
  38.    end loop;
  39.  
  40.    Put_Line("Begin non-accumulative timing loop here.");
  41.  
  42.    Time_And_Date := Clock;
  43.    Split(Time_And_Date,Year,Month,Day,Start);  -- get starting time
  44.    for Index in 1..9 loop
  45.       Time_And_Date := Clock;
  46.       Split(Time_And_Date,Year,Month,Day,Seconds);
  47.       Put("The elapsed time is");
  48.       Put(Seconds - Start,8,3,0);
  49.       New_Line;
  50.       delay DAY_DURATION(Index) - (Seconds - Start);
  51.    end loop;
  52. end Timer;
  53.  
  54. -- Result of Execution
  55.  
  56. -- Begin 3.14 second delay
  57. -- End of 3.14 second delay
  58. -- The date and time are now  7 22 1988        0.000
  59. -- The date and time are now  7 22 1988        1.090
  60. -- The date and time are now  7 22 1988        2.140
  61. -- The date and time are now  7 22 1988        3.180
  62. -- The date and time are now  7 22 1988        4.230
  63. -- The date and time are now  7 22 1988        5.270
  64. -- The date and time are now  7 22 1988        6.320
  65. -- The date and time are now  7 22 1988        7.360
  66. -- The date and time are now  7 22 1988        8.400
  67. -- Begin non-accumulative timing loop here
  68. -- The elapsed time is       0.000
  69. -- The elapsed time is       1.100
  70. -- The elapsed time is       2.030
  71. -- The elapsed time is       3.020
  72. -- The elapsed time is       4.040
  73. -- The elapsed time is       5.030
  74. -- The elapsed time is       6.020
  75. -- The elapsed time is       7.010
  76. -- The elapsed time is       8.000
  77.  
  78.