/mobile Handheld Friendly website

 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,0003.353.379,856602  1% 2% 1% 100%
5,000,00033.7033.749,856602  1% 1% 0% 100%
50,000,000340.33340.569,860602  1% 1% 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.

 notes

GNAT 4.6

gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)

 thread-ring Ada 2005 GNAT program source code

-- The Computer Language Benchmarks Game

-- http://benchmarksgame.alioth.debian.org/

-- contributed by Jim Rogers


with Ada.Text_Io; use Ada.Text_Io;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure ThreadRing is
   
   protected Flag is
      procedure Set(Num : Positive);
      entry Wait(Last : out Positive);
   private
      Done : Boolean := False;
      Id : Positive;
   end Flag;
   protected body Flag is
      procedure Set(Num : Positive) is
      begin
         Done := True;
         Id := Num;
      end Set;
      entry Wait(Last : out Positive) when Done is
      begin
         Last := Id;
      end Wait;
   end Flag;

   type Node;
   type Node_Access is access Node;
   
   Ring : array(1..503) of Node_Access;
   
   task type Node(Id : Positive) is
      entry Start(Next : Node_Access);
      entry Put(Item : in Natural);
      entry Stop;
   end Node;
   
   task body Node is
      Val : Natural;
      Next_Node : Node_Access;
   begin
      accept Start(Next : Node_Access) do
         Next_Node := Next;
      end Start;
      
      loop
         select
            accept Put(Item : in Natural) do
               Val := Item;
            end Put;
         or
            accept Stop;
            exit;
         end select;
         if Val > 0 then
            Val := Val - 1;
            Next_Node.Put(Val);
         else
            Flag.Set(Id);
         end if;
      end loop;
   end Node;
   
   Num_Passes : Natural;
   Last_Node : Positive;
begin
   Num_Passes := Natural'Value(Argument(1));
   for I in Ring'range loop
      Ring(I) := new Node(I);
   end loop;
   Ring(Ring'Last).Start(Ring(1));
   for I in Ring'First..Ring'Last - 1 loop
      Ring(I).Start(Ring(I + 1));
   end loop;
   Ring(1).Put(Num_Passes);
   Flag.Wait(Last_Node);
   Put(Item => Last_Node, Width => 1);
   New_Line;
   for I in Ring'range loop
      Ring(I).Stop;
   end loop;
   
end ThreadRing;

 make, command-line, and program output logs

Mon, 21 Oct 2013 19:26:56 GMT

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

COMMAND LINE:
./threadring.gnat_run 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play