Anonymous user
Rate counter: Difference between revisions
m
→{{header|Ada}}: simplify code
(Ada implementation) |
m (→{{header|Ada}}: simplify code) |
||
Line 14:
=={{header|Ada}}==
Launch 6 jobs in parallel and record the elapsed time for each job.
The precision of measure is given by the value of System.Tick; on Windows value is 10 ms.
<lang Ada>with System; use System;
with
with Ada.
procedure Rate_Counter is
Line 40 ⟶ 38:
Jobs : array (Job_Index) of Job_Ptr;
Completed : array (Job_Index) of
Start_T, Stop_T : array (Job_Index) of Calendar.Time;▼
Start_T, Stop_T : Timings;
task body Job is
Line 51 ⟶ 48:
pragma Volatile (Anchor); -- necessary to avoid compiler optimization.
begin
accept Start
-- the job
▲ for I in Long_Integer'First .. Long_Integer'Last loop
Anchor := I;
end loop;
end Job;
Line 69 ⟶ 63:
Jobs (J).Start; -- priority settings necessary to regain control.
end loop;
-- Polling for the results / also possible to use a protected type.
while not (Done = Job_Nbr) loop
for J in Job_Index'Range loop
if not Completed (J) and then
Stop_T (J) := Calendar.Clock; -- get the end time
Put ("Job #" & Job_Index'Image (J) & " is finished. It took ");
Line 83 ⟶ 77:
delay System.Tick; -- according to the precision of the system clock
end loop;
Duration_IO.Put (System.Tick, Fore => 1, Aft => 3);
Put_Line (" seconds is the precision of System clock.");
end Rate_Counter;</lang>
Output :
Job # 1 is finished. It took 44.49 seconds.▼
Job #
Job #
Job #
Job #
Job #
0.010 seconds is the precision of System clock.</pre>
=={{header|C}}==
|