From: "Steve Doiel" <nospam_steved@pacifier.com>
Subject: Re: ADA code execution times
Date: 1998/08/02
Date: 1998-08-02T00:00:00+00:00 [thread overview]
Message-ID: <35c4e297.0@news.pacifier.com> (raw)
In-Reply-To: 35c354e5.140587456@news.gatech.edu
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;
next prev parent reply other threads:[~1998-08-02 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-01 0:00 ADA code execution times Brian Franklin
1998-08-01 0:00 ` Tom Moran
1998-08-02 0:00 ` Jerry van Dijk
1998-08-02 0:00 ` Steve Doiel [this message]
1998-08-03 0:00 ` dennison
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox