performance measurements

Each table row shows performance measurements for this Ada 2005 GNAT program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0002.062.0817,076727  0% 1% 0% 99%
5,000,00019.6419.6616,788727  1% 0% 0% 100%
50,000,000199.24199.3416,956727  0% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.



gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)

 thread-ring Ada 2005 GNAT #3 program source code

-- The Computer Language Benchmarks Game
--  Contributed by Francois Fabien (23 octobre 2011)
-- Os threads are Ada tasks. Transfer of control is done synchronously by an
-- array of semaphores using a predefined Ada package.
-- The token is a global data that needs no protection since only one
-- thread at a time will use it.
-- Directives are in the source code, so compile only with:
--    gnatchop threadring.gnat
--    gnatmake -O3 -gnatn -march=native threadring.adb
pragma Suppress (All_Checks); -- go for speed not safety
-- pragmas used for optimization of the run-time.
pragma Restrictions (No_Abort_Statements);
pragma Restrictions (Max_Asynchronous_Select_Nesting => 0);


with Ada.Command_Line;             use Ada.Command_Line;
with Ada.Synchronous_Task_Control; use Ada;
with Threadring_Pool;              use Threadring_Pool;

pragma Elaborate_All (Threadring_Pool);

procedure Threadring is
   -- GNU ld will remove unused sections; GNAT specific
   pragma Linker_Options ("-Wl,--gc-sections");

   if Argument_Count > 0 then
      Token := Tokens'Value (Argument (1));
   end if;
   Synchronous_Task_Control.Set_True (Semaphores (Ring_Nbr'First));

end Threadring;

with Ada.Synchronous_Task_Control; use Ada, Ada.Synchronous_Task_Control;

package Threadring_Pool is

   Ring_Size : constant := 503;
   type Ring_Nbr is range 1 .. Ring_Size;

   type Tokens is range -1 .. +(2 ** 31 - 1);
   ---- -1 => flag for task termination
   for Tokens'Size use 32;

   Token : Tokens := 2 * Ring_Size - 1; -- default value for testing

   Semaphores : array (Ring_Nbr) of Suspension_Object;


   task type Threads is
      entry Initialize (Identifier : in Ring_Nbr);
   end Threads;

   Ring : array (Ring_Nbr) of Threads;

end Threadring_Pool;

with Ada.Text_IO; use Ada.Text_IO;

package body Threadring_Pool is

   package Ring_IO is new Integer_IO (Ring_Nbr);

   task body Threads is
      ID, Next : Ring_Nbr;
      accept Initialize (Identifier : in Ring_Nbr) do
         ID   := Identifier;
         Next := ID mod Ring_Size + 1;
         Set_False (Semaphores (ID));
      end Initialize;

         Suspend_Until_True (Semaphores (ID));
         Set_False (Semaphores (ID));
         if Token > 0 then
            Token := Token - 1;
            Set_True (Semaphores (Next));
         end if;
      end loop;

      if Token = 0 then
         Ring_IO.Put (ID, Width => 0);
         Token := -1;
      end if;
      Set_True (Semaphores (Next));
   end Threads;

   for T in Ring'Range loop
      Ring (T).Initialize (Identifier => T);
   end loop;
end Threadring_Pool;

 make, command-line, and program output logs

Mon, 18 May 2015 18:31:45 GMT

/usr/bin/gnatchop -r -w threadring.gnat-3.gnat
splitting threadring.gnat-3.gnat into:
/usr/bin/gnatmake -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -gnatNp -f threadring.adb -o threadring.gnat-3.gnat_run 
gcc-4.9 -c -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -gnatNp threadring.adb
gcc-4.9 -c -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -gnatNp threadring_pool.adb
gnatbind -x threadring.ali
gnatlink threadring.ali -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -o threadring.gnat-3.gnat_run
0.76s to complete and log all make actions

./threadring.gnat-3.gnat_run 50000000


Revised BSD license

  Home   Conclusions   License   Play