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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a889ad4a86a5caa4 X-Google-Attributes: gid103376,public From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) Subject: Re: ADA code execution times Date: 1998/08/02 Message-ID: #1/1 X-Deja-AN: 377123027 References: <35c354e5.140587456@news.gatech.edu> Organization: * JerryWare *, Leiden, Holland Newsgroups: comp.lang.ada Date: 1998-08-02T00:00:00+00:00 List-Id: Brian Franklin (bf14@prism.gatech.edu) wrote: : I asked this question before and received some replies which were of : some use but no answers. So I'll ask again... Well, actually you did get the answers. : What code can I use in my ADA program to report the time. : OS: Windows 95 : Compiler: GNAT : Processor: Pentium To anser again: In the Win32 enviroment there is, to my knowledge, no way to get more accurate timing than about 1/10th of a second without using a realtime kernel. You said you needed millisecond accuracy. As Tom already said, the QueryPerformance* functions are probably the most accurate. However, try to run the test program below several times, and see for yourself how accurate the results are. -- test.adb with Win_Timer; with Ada.Text_IO; procedure Test is Start, Stop : Long_Long_Integer; begin Start := Win_Timer.Get_Current_Count; delay 1.234; Stop := Win_Timer.Get_Current_Count; Ada.Text_IO.Put_Line ("Start:" & Start'Img); Ada.Text_IO.Put_Line ("Stop: " & Stop'Img); Ada.Text_IO.Put_Line ("Time: " & Integer'Image (Win_Timer.Get_Time (Start, Stop))); end Test; -- win_timer.ads package Win_Timer is function Get_Current_Count return Long_Long_Integer; -- get current count function Get_Time (T1, T2 : Long_Long_Integer) return Integer; -- get time difference between T1 and T2 in milliseconds No_Counter_Error : exception; Counter_Read_Error : exception; Invalid_Count_Error : exception; private pragma Inline (Get_Time); pragma Inline (Get_Current_Count); end Win_Timer; -- win_timer.adb package body Win_Timer is type Long_Long_Pointer is access all Long_Long_Integer; -- pointer to 64-bit integer Temp_Value : aliased Long_Long_Integer; -- 64-bit integer buffer Frequency : aliased Long_Long_Integer; -- counter frequency Frequency_Pointer : Long_Long_Pointer := Frequency'Access; -- pointer to counter frequency --------------------- -- Win32 interface -- --------------------- function QueryPerformanceCounter (Count : in Long_Long_Pointer) return Integer; pragma Import (StdCall, QueryPerformanceCounter, "QueryPerformanceCounter"); function QueryPerformanceFrequency (Frequency : in Long_Long_Pointer) return Integer; pragma Import (StdCall, QueryPerformanceFrequency, "QueryPerformanceFrequency"); ----------------------- -- get current count -- ----------------------- function Get_Current_Count return Long_Long_Integer is Value : Long_Long_Pointer := Temp_Value'Access; begin if QueryPerformanceCounter (Value) = 0 then raise Counter_Read_Error; end if; return Value.all; end Get_Current_Count; ----------------------------------------------------------- -- get time difference between T1 and T2 in milliseconds -- ----------------------------------------------------------- function Get_Time (T1, T2 : Long_Long_Integer) return Integer is Dif : Long_Long_Integer := T2 - T1; begin if T1 > T2 then raise Invalid_Count_Error; end if; return Integer ((1_000 * Dif) / Frequency); end; --------------------------- -- get counter frequency -- --------------------------- begin if QueryPerformanceFrequency (Frequency_Pointer) = 0 then raise No_Counter_Error; end if; end Win_Timer; -- -- Jerry van Dijk | email: jdijk@acm.org -- Leiden, Holland | member Team-Ada -- Ada & Win32: http://stad.dsl.nl/~jvandyk