comp.lang.ada
 help / color / mirror / Atom feed
* Task execution time 2
@ 2010-12-30  8:54 Dmitry A. Kazakov
  0 siblings, 0 replies; only message in thread
From: Dmitry A. Kazakov @ 2010-12-30  8:54 UTC (permalink / raw)


Here is a better test for the thing. It measures the execution time using
real-time clock and Windows services. The idea is to give up the processor
after 0.5ms, before the system time quant expires.

The test must run considerably long time. Because the task Measured should
lose the processor each 0.5ms and return back after other tasks would take
their share. If the test completes shortly, that possibly mean something
wrong. Increase the number of worker task.
----------------------------------------------------------------
with Ada.Execution_Time;  use Ada.Execution_Time;
with Ada.Real_Time;       use Ada.Real_Time;
with Ada.Text_IO;         use Ada.Text_IO;

with Ada.Numerics.Elementary_Functions;

procedure Executuion_Time_1 is
   task type Measured;
   task body Measured is
      Count     : Seconds_Count;
      Fraction  : Time_Span;
      Estimated : Time_Span := Time_Span_Zero;
      Start     : Time;
   begin
      for I in 1..1_000 loop
         Start := Clock;
         while To_Duration (Clock - Start) < 0.000_5 loop
            null;
         end loop;
         Estimated := Estimated + Clock - Start;
         delay 0.0;
      end loop;
      Split (Ada.Execution_Time.Clock, Count, Fraction);
      Put_Line
      (  "Measured: seconds" & Seconds_Count'Image (Count) &
         " Fraction " & Duration'Image (To_Duration (Fraction))
      );
      Put_Line
      (  "Estimated:" & Duration'Image (To_Duration (Estimated))
      );
   end Measured;

   task type Worker; -- Used to generate CPU load
   task body Worker is
      use Ada.Numerics.Elementary_Functions;
      X : Float;
   begin
      for I in Positive'Range loop
         X := sin (Float (I));
      end loop;
   end Worker;

begin
   delay 0.1;
   declare
      Workers : array (1..5) of Worker;
      Test    : Measured;
   begin
      null;
   end;
end Executuion_Time_1;
-----------------------------------------------------------
Windows XP SP3

Measured: seconds 0 Fraction  0.000000000
Estimated: 0.690618774

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-30  8:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-30  8:54 Task execution time 2 Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox