comp.lang.ada
 help / color / mirror / Atom feed
* Fairly simple question about using time in Ada
@ 2001-09-29  1:26 Chris Vinall
  2001-09-29  2:33 ` James Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Chris Vinall @ 2001-09-29  1:26 UTC (permalink / raw)


I'm writing a program in which I need to be able to timestamp events and
then later check how much real time has elapsed since that event occurred.
It is essential that this timing operate to tenths of a second and
hundredths of a second would be a lot better.

How do I go about doing this in Ada? My textbook mentioned something about
Duration but was less than helpful.

Thanks for any help

Chris





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29  1:26 Fairly simple question about using time in Ada Chris Vinall
@ 2001-09-29  2:33 ` James Rogers
  2001-10-02  5:56   ` tmoran
  2001-09-29 12:44 ` DuckE
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: James Rogers @ 2001-09-29  2:33 UTC (permalink / raw)


Chris,

I hope you have access to a copy of the Language Reference Manual.
It is very helpful.

You want to use the Ada.Calendar package. This package defines a number
of useful types and subprograms.

The "time" type is used to hold an absolute time value. Its resolution
is at least to the 0.1 millisecond level.

The Ada.Calendar package also defines a function taking no parameters
called "clock". Clock returns a time value (the current time). There
is also a definition of the subtraction function "-" for two time
values. This function returns a duration value. 

Duration is defined as a fixed-point type. Values to the left of the
radix (decimal point) represent whole seconds. Values to the right
of the radix represent fractional seconds.

A duration value of 10.001 would then represent 10 seconds plus one
millisecond.

I hope this information helps. 

Just a little note, the Ada.Calendar.Time type is useful for
relatively gross timings. If you want finer timing capability you
need to use a compiler implementing the Real-Time annex for Ada.
This will allow you to time events to a granularity no rougher 
than 0.1 microseconds. I assume you will not be needing such
a fine level of timing.

Jim Rogers
Colorado Springs, Colorado USA

Chris Vinall wrote:
> 
> I'm writing a program in which I need to be able to timestamp events and
> then later check how much real time has elapsed since that event occurred.
> It is essential that this timing operate to tenths of a second and
> hundredths of a second would be a lot better.
> 
> How do I go about doing this in Ada? My textbook mentioned something about
> Duration but was less than helpful.
> 
> Thanks for any help
> 
> Chris



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29  1:26 Fairly simple question about using time in Ada Chris Vinall
  2001-09-29  2:33 ` James Rogers
@ 2001-09-29 12:44 ` DuckE
  2001-10-03 10:27   ` Petter Fryklund
  2001-10-04 10:03 ` Alfred Hilscher
  2001-10-04 17:56 ` R. Tim Coslet
  3 siblings, 1 reply; 8+ messages in thread
From: DuckE @ 2001-09-29 12:44 UTC (permalink / raw)


Here is what I usually do:

WITH Ada.Text_Io;
WITH Ada.Float_Text_Io;

PROCEDURE Elapsed_Time_Demo IS

  PACKAGE Text_Io RENAMES Ada.Text_Io;
  PACKAGE Float_Text_Io RENAMES Ada.Float_Text_Io;
  PACKAGE Real_Time RENAMES Ada.Real_Time;
  USE TYPE Real_Time.Time;

  start_time   : Real_Time.Time;
  end_Time     : Real_Time.Time;
  elapsed_time : Real_Time.Time_Span;

BEGIN
  start_time := Real_Time.Clock;
  FOR ii IN 1 .. 1_000_000 LOOP  -- Something that needs timing
    NULL;                        --
  END LOOP;                      --
  end_time := Real_Time.Clock;
  elapsed_time := end_time - start_time;
  Text_Io.Put( "Elapsed time is: " );
  Float_Text_Io.Put( Float( Real_Time.To_Duration( elapsed_Time ) ), 3, 2,
0 );
END Elapsed_Time_Demo;


"Chris Vinall" <cjvinall@dingoblue.net.au> wrote in message
news:3bb5234f$0$9274$afc38c87@news.optusnet.com.au...
> I'm writing a program in which I need to be able to timestamp events and
> then later check how much real time has elapsed since that event occurred.
> It is essential that this timing operate to tenths of a second and
> hundredths of a second would be a lot better.
>
> How do I go about doing this in Ada? My textbook mentioned something about
> Duration but was less than helpful.
>
> Thanks for any help
>
> Chris
>
>





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29  2:33 ` James Rogers
@ 2001-10-02  5:56   ` tmoran
  0 siblings, 0 replies; 8+ messages in thread
From: tmoran @ 2001-10-02  5:56 UTC (permalink / raw)


>The "time" type is used to hold an absolute time value. Its resolution
>is at least to the 0.1 millisecond level.
  Many compilers depend on the clock time, which on (DOS or) Windows
systems can be quite long.  There's a test program on www.adapower.com
Search for "timing the clock".



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29 12:44 ` DuckE
@ 2001-10-03 10:27   ` Petter Fryklund
  0 siblings, 0 replies; 8+ messages in thread
From: Petter Fryklund @ 2001-10-03 10:27 UTC (permalink / raw)


This will be very unaccurate on many systems, since Real_Time.Clock also has
a substansial granularity.






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29  1:26 Fairly simple question about using time in Ada Chris Vinall
  2001-09-29  2:33 ` James Rogers
  2001-09-29 12:44 ` DuckE
@ 2001-10-04 10:03 ` Alfred Hilscher
  2001-10-04 17:56 ` R. Tim Coslet
  3 siblings, 0 replies; 8+ messages in thread
From: Alfred Hilscher @ 2001-10-04 10:03 UTC (permalink / raw)




Chris Vinall wrote:
> 
> I'm writing a program in which I need to be able to timestamp events and
> then later check how much real time has elapsed since that event occurred.
> It is essential that this timing operate to tenths of a second and
> hundredths of a second would be a lot better.
> 
> How do I go about doing this in Ada? My textbook mentioned something about
> Duration but was less than helpful.


Hi,

I did some tests with the "Calendar" package sometime ago. I found, that
while GNAT (on WinNT) has a pretty good accurcy, the ObjectAda that I
have (the free version), has a worse resolution. So I use some OS-calls
now. If you work on Windows, you can get the code from me.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-09-29  1:26 Fairly simple question about using time in Ada Chris Vinall
                   ` (2 preceding siblings ...)
  2001-10-04 10:03 ` Alfred Hilscher
@ 2001-10-04 17:56 ` R. Tim Coslet
  2001-10-04 19:44   ` tmoran
  3 siblings, 1 reply; 8+ messages in thread
From: R. Tim Coslet @ 2001-10-04 17:56 UTC (permalink / raw)


"Chris Vinall" <cjvinall@dingoblue.net.au> wrote in message news:<3bb5234f$0$9274$afc38c87@news.optusnet.com.au>...
> I'm writing a program in which I need to be able to timestamp events and
> then later check how much real time has elapsed since that event occurred.
> It is essential that this timing operate to tenths of a second and
> hundredths of a second would be a lot better.
> 
> How do I go about doing this in Ada? My textbook mentioned something about
> Duration but was less than helpful.
> 
> Thanks for any help
> 
> Chris

See D.8(7)

To correctly do time stamping you need the package Ada.Real_Time
The constant Tick gives the timing accuracy of your implementation of
this package.

You would call the function Clock to get the current Time for use in
generating your time stamps.


Please note that other posters have not differentatiated between the
accuracy of a number and the precision of a number. They are
different! What you need for good time stamps is accuracy (fidelity to
reality), not precision (number of bits or digits used to represent
the value).



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fairly simple question about using time in Ada
  2001-10-04 17:56 ` R. Tim Coslet
@ 2001-10-04 19:44   ` tmoran
  0 siblings, 0 replies; 8+ messages in thread
From: tmoran @ 2001-10-04 19:44 UTC (permalink / raw)


>accuracy of a number and the precision of a number. They are
>different! What you need for good time stamps is accuracy (fidelity to
>reality), not precision (number of bits or digits used to represent
>the value).
  Accuracy is what www.adapower.com/reuse/tt.html is about.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-10-04 19:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-29  1:26 Fairly simple question about using time in Ada Chris Vinall
2001-09-29  2:33 ` James Rogers
2001-10-02  5:56   ` tmoran
2001-09-29 12:44 ` DuckE
2001-10-03 10:27   ` Petter Fryklund
2001-10-04 10:03 ` Alfred Hilscher
2001-10-04 17:56 ` R. Tim Coslet
2001-10-04 19:44   ` tmoran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox