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: "Steve Doiel" Subject: Re: ADA code execution times Date: 1998/08/02 Message-ID: <35c4e297.0@news.pacifier.com>#1/1 X-Deja-AN: 377305555 References: <35c354e5.140587456@news.gatech.edu> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Date: 1998-08-02T00:00:00+00:00 List-Id: Brian Franklin wrote in message <35c354e5.140587456@news.gatech.edu>... >I asked this question before and received some replies which were of >some use but no answers. So I'll ask again... > >What code can I use in my ADA program to report the time. I want to >get an estimate of the execution time. Getting the CPU time seems >somewhat complicated so I'll settle for getting the time at the start >and finish of the process in order to get an estimate of the >performance of the code. Here is some code I used to compare the time of using a task versus a protected type to implement a semaphore. My basic technique is to capture the time before performing the thing I want to time, perform the operation multiple times, and then capture the time at the end . Right, wrong, or indifferent I figure that timing for one iteration would introduce too much error due to the low resolution available on the PC's clock, so timing a bunch of iterations reduces the error. You're question about timing is somewhat vague. Is this what you're looking for? If not, maybe you're looking for a profiler? I guess my ESP level isn't that high. SteveD Sample Code: with ada; use ada; with Text_Io; with Ada.Float_Text_Io; with Ada.Integer_Text_Io; with Ada.Real_Time; procedure Timing is use type Real_Time.time; use type Real_Time.time_span; protected type TSemaphore is entry Take; procedure Give; entry WaitBlocked; private isBlocked : BOOLEAN := FALSE; end TSemaphore; protected body TSemaphore is entry Take when NOT isBlocked is begin isBlocked := TRUE; end Take; procedure Give is begin isBlocked := FALSE; end Give; entry WaitBlocked when isBlocked is begin null; end WaitBlocked; end TSemaphore; task type TTaskSem is entry Take; entry Give; end TTaskSem; task body TTaskSem is isBlocked : BOOLEAN := FALSE; begin loop select when not isBlocked => accept Take do isBlocked := TRUE; end Take; or accept Give do isBlocked := FALSE; end Give; end select; end loop; end TTaskSem; startTime : Real_Time.Time; endTime : Real_Time.Time; tareTime : Real_Time.Time_Span; timeInSeconds : float; iterations : constant := 100_000; sem : TSemaphore; taskSem : TTaskSem; task flusher is end; task body flusher is begin loop sem.WaitBlocked; sem.Give; end loop; end flusher; begin Text_Io.Put_Line( "Started" ); startTime := Real_Time.Clock; for ii in 1..iterations loop null; end loop; endTime := Real_Time.Clock; Text_Io.Put( "Time for " ); Integer_Text_Io.Put( iterations, 1 ); Text_Io.Put( " iterations of empty loop is " ); timeInSeconds := Float((endTime - startTime)/Real_Time.Milliseconds(1))* 0.001; Float_Text_Io.Put( timeInSeconds, 3, 3, 0 ); Text_Io.Put_Line( " msec" ); startTime := Real_Time.Clock; for ii in 1..iterations loop sem.Take; -- sem.Give; end loop; endTime := Real_Time.Clock; Text_Io.Put( "Time for " ); Integer_Text_Io.Put( iterations, 1 ); Text_Io.Put( " iterations of protected take/give loop is " ); timeInSeconds := Float((endTime - startTime)/Real_Time.Milliseconds(1))* 0.001; Float_Text_Io.Put( timeInSeconds, 3, 3, 0 ); Text_Io.Put_Line( " msec" ); startTime := Real_Time.Clock; for ii in 1..iterations loop taskSem.Take; taskSem.Give; end loop; endTime := Real_Time.Clock; Text_Io.Put( "Time for " ); Integer_Text_Io.Put( iterations, 1 ); Text_Io.Put( " iterations of task take/give loop is " ); timeInSeconds := Float((endTime - startTime)/Real_Time.Milliseconds(1))* 0.001; Float_Text_Io.Put( timeInSeconds, 3, 3, 0 ); Text_Io.Put_Line( " msec" ); abort taskSem; abort flusher; Text_Io.Put_Line( "Complete!" ); end Timing;