comp.lang.ada
 help / color / mirror / Atom feed
* Task execution time test
@ 2010-12-26 10:25 Dmitry A. Kazakov
  2010-12-29 23:00 ` h_poincare
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2010-12-26 10:25 UTC (permalink / raw)


Here is a small test for task execution time.

Five worker tasks are used to generate background CPU load. When the
measured task enters delay 0.1ms (on a system where delay is non-busy) it
should lose the CPU prematurely.

Under at least some Windows systems the test might fail because Windows
performance counters are CPU quants 1ms or 10ms, depending on settings.

Under VxWorks the test may fail because real-time clock there is driven by
the timer interrupts, so it is impossible to have non-busy wait for 0.1ms.

(I cannot say anything about Linux, because I never used it for RT
applications, maybe other people could comment)

----------------------------------------------------
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 is
   task type Measured;
   task body Measured is
      Count    : Seconds_Count;
      Fraction : Time_Span;
   begin
      for I in 1..1_000 loop
         delay 0.000_1;
      end loop;
      Split (Ada.Execution_Time.Clock, Count, Fraction);
      Put_Line
      (  "Seconds" & Seconds_Count'Image (Count) &
         " Fraction" & Duration'Image (To_Duration (Fraction))
      );
   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; -- This might be needed for some buggy versions of GNAT
   declare
      Workers : array (1..5) of Worker;
      Test    : Measured;
   begin
      null;
   end;
end Executuion_Time;
-----------------------------------------------------
On my Windows XP SP3 the test yields 0-0.

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-30  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-26 10:25 Task execution time test Dmitry A. Kazakov
2010-12-29 23:00 ` h_poincare
2010-12-30  8:54   ` 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