From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d1f23f0bd3971bec X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 21 Apr 2005 19:58:18 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1114090119.383842.20950@l41g2000cwc.googlegroups.com> Subject: Re: Timing Block of GNAT code in milliseconds Date: Thu, 21 Apr 2005 18:00:24 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Message-ID: <1KydnfadqcK30fXfRVn-qw@comcast.com> NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-cyXamDzQlCywxDxkfSvasEa8XDeim9hHudIQcslDeJlYuYzk9xyZ7cunqau/+fw+coAvR+h/2hT2d9s!X5AXPLVndb+3TniAbuV3cFC+PJfBJ8ivELzE6+mxoTIxm3meX+1Sncj41lvV X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.31 Xref: g2news1.google.com comp.lang.ada:10635 Date: 2005-04-21T18:00:24-07:00 List-Id: Actually I think this is a better job for Ada.Real_Time than Ada.Calendar. I usually do something like: start_time := Ada.Real_Time.Clock; .. do something end_time := Ada.Real_Time.Clock; elapsed_seconds := Float( To_Duration( end_time - start_time ) ); I tend to think of the Real_Time package as the one to use when you are timing events and the Calendar package as the one to use when you don't care about precise timing and want the time of day for reporting, etc. Steve (The Duck) wrote in message news:HI2dnf8gWoC-d_rfRVn-sQ@comcast.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;