[comp.lang.ada] HELP! HELP! HELP! need to display DURATION type

llb4901@cec2.wustl.edu (Lonnie Lee Blackwood) (04/09/91)

We are doing a timing analysis on our Ada program and need to display
the # seconds elapsed, which is type DURATION.

DURATION is larger than an integer, so it can't be PUT in the same way.

Any help would be appreciated!


Lonnie Blackwood
llb4901@cec2.wustl.edu

rlk@telesoft.com (Bob Kitzberger @sation) (04/12/91)

In some article Lonnie Lee Blackwood writes:

> We are doing a timing analysis on our Ada program and need to display
> the # seconds elapsed, which is type DURATION.
> 
> DURATION is larger than an integer, so it can't be PUT in the same way.

Try this:

	package Duration_IO is new Text_IO.Fixed_IO( Duration );

	Nostril_Hair : Duration := 47.47;

	  .
	  .
	  Duration_IO.Put( Nostril_Hair );
	  Text_IO.New_Line;
	  .
	  .

I didn't run this through a syntax check, so shoot me if your compiler
complains ;-)

See LRM 14.3.8 for more info.

	.Bob.

p.s. There are many gotchas associated with measuring time with elements of
type duration.  A few quickies:

	1. Duration'Small may be too large for the accuracy you want.

	2. Round-off errors in converting from type Duration to other
	   types.

	3. The hardware timers (and the device drivers that implement 
	   Calendar.Clock and DELAY on top of these hardware timers) may 
	   have a resolution that is worse than Duration'Small.  For 
	   example, Duration'Small is usually 2**-14 (about 61 microseconds)
	   but the underlying timer may provide resolution in the
	   millisecond range.  Often you can adapt this portion of the
	   run-time system of your compiler to suit your needs.

    I don't mean to dissuade you from using values of type Duration...
    just to point out some potential problem areas. 

    Lest I make a full-blown article out of this p.s., I'll close with
    a reference about using Ada's timing model:

       Ted Baker, "Fixing some time-related problems in Ada".  In
       _Proceedings of the Third International Conference on Real-Time
       Ada Issues (1989).

       Nelson Weiderman, "Real-Time Programmers Don't Use Calendars."
       In _Proceedings of the Third International Conference on Real-Time
       Ada Issues (1989).
-- 
Bob Kitzberger               Internet : rlk@telesoft.com
TeleSoft                     uucp     : ...!ucsd.ucsd.edu!telesoft!rlk
5959 Cornerstone Court West, San Diego, CA  92121-9891  (619) 457-2700 x163
------------------------------------------------------------------------------
"Wretches, utter wretches, keep your hands from beans!"	-- Empedocles

mfeldman@seas.gwu.edu (Michael Feldman) (04/12/91)

In article <1991Apr9.034421.7397@cec1.wustl.edu> llb4901@cec2.wustl.edu (Lonnie Lee Blackwood) writes:
>We are doing a timing analysis on our Ada program and need to display
>the # seconds elapsed, which is type DURATION.
>
>DURATION is larger than an integer, so it can't be PUT in the same way.
>
>Any help would be appreciated!

How about putting the following in your program library:

WITH Text_IO;
PACKAGE Duration_IO IS NEW Text_IO.Fixed_IO(Num=>Duration);

in subsequent programs, just "with" Duration_IO. Since Duration is
just a fixed-point type, this will work fine (I've done it before).

Keep the following in mind: if your program is running on a timesharing
system, Calendar gives REAL TIME (WALLCLOCK), not the CPU time used
by your program. (On a PC, since you're the only user, the two times
are equivalent)

I can post a Unix-oriented CPU timing package that interfaces to C,
to get CPU time from Unix timing services. Anyone interested?

Mike Feldman