comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Timing Block of GNAT code in milliseconds
Date: Thu, 21 Apr 2005 13:00:03 -0500
Date: 2005-04-21T13:00:03-05:00	[thread overview]
Message-ID: <HI2dnf8gWoC-d_rfRVn-sQ@comcast.com> (raw)
In-Reply-To: 1114090119.383842.20950@l41g2000cwc.googlegroups.com

>I am trying to time a block of code down to the millisecond level. Can
>anyone help in this area?
   The traditional way is
     T0 := Ada.Calendar.Clock;
     for i in 1 .. 1000 loop
       -- code to be timed
     end loop;
     Result := (Ada.Calendar.Clock - T0)/1000;
If the code to be timed is short so the loop overhead is significant, then
you time an empty loop (making sure the compiler doesn't optimize it away)
and subtract that.  On Windows machines it doesn't take long to call
Ada.Calendar.Clock, and that's accurate to better than one microsecond, so
if you want millisecond accuracy you could even dispense with the loop and
just do
     T0 := Ada.Calendar.Clock;
       -- code to be timed
     Result := (Ada.Calendar.Clock - T0)/1000;



  reply	other threads:[~2005-04-21 18:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-21 13:28 Timing Block of GNAT code in milliseconds markp
2005-04-21 18:00 ` tmoran [this message]
2005-04-21 18:53   ` markp
2005-04-21 19:40     ` Marc A. Criley
2005-04-21 19:44     ` Simon Wright
2005-04-22  1:00   ` Steve
2005-04-23  5:39     ` Simon Wright
2005-04-23 17:49       ` Steve
2005-04-24 18:57         ` Simon Wright
2005-04-24 20:05           ` Dmitry A. Kazakov
2005-04-25 22:56             ` Randy Brukardt
2005-04-28 20:26             ` Simon Wright
2005-04-29  8:11               ` Dmitry A. Kazakov
2005-04-29 18:25                 ` tmoran
2005-04-29 19:19                   ` Dmitry A. Kazakov
2005-04-29 20:24                     ` tmoran
2005-04-30  9:47                       ` Dmitry A. Kazakov
2005-04-29 20:52                 ` Randy Brukardt
2005-04-30 10:02                   ` Dmitry A. Kazakov
replies disabled

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