comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <carter@innocon.com>
Subject: Re: Ada versus Java - Tasking
Date: 1997/01/17
Date: 1997-01-17T00:00:00+00:00	[thread overview]
Message-ID: <32DFC320.41C67EA6@innocon.com> (raw)
In-Reply-To: 01bc03ee$594dc520$829d6482@joy.ericsson.se


Jonas Nygren wrote:
> 
> I have written a small producer-consumer type of program
> both in Ada and Java. To my astonishment the Java code
> executes faster than the Ada code.
> 
> My test starts 50 producer-consumer pairs that run in
> parallell. Each pair produces/consumes 1000 messages
> of 50 bytes. I get the following timing on my P133,
> 16M, and running Win95:
> 
> Ada  (Gnat 3.04a)  : ~30 s

This seems excessive; see below.

> Java (MS SDK-Java) : ~15 s
> 
> ...
>
> ... the Ada version
> stopped working already when 63 pairs were started
> (62 pairs would run).

I too encountered this limitation.

Here's my version:

with Interfaces;
with Ada.Calendar;
with Ada.Text_Io;
 
use Ada;
procedure Prod_Cons is
   procedure Time_This is
      type Data_Block is array (1 .. 50) of Interfaces.Unsigned_8;
      for Data_Block'Component_Size use Interfaces.Unsigned_8'Size;
      for Data_Block'Size use 50 * Interfaces.Unsigned_8'Size;
   
      task type Consumer_Agent is
         entry Put (Data : in Data_Block);
      end Consumer_Agent;
      type Consumer_Ptr is access all Consumer_Agent;
   
      task type Producer_Agent (Consumer : access Consumer_Agent);
      type Producer_Ptr is access all Producer_Agent;
   
      task body Consumer_Agent is
         Local : Data_Block;
      begin -- Consumer_Agent
         Forever : loop
            select
               accept Put (Data : in Data_Block) do
                  Local := Data;
               end Put;
            or
               terminate;
            end select;
         end loop Forever;
      end Consumer_Agent;
   
      task body Producer_Agent is
         Data : Data_Block := (others => 0);
      begin -- Producer_Agent
         All_Data : for I in 1 .. 1000 loop
            Consumer.Put (Data => Data);
         end loop All_Data;
      end Producer_Agent;
   
      Consumer : Consumer_Ptr;
      Producer : Producer_Ptr;
   begin -- Time_This
      All_Pairs : for I in 1 .. 50 loop
         Consumer := new Consumer_Agent;
         Producer := new Producer_Agent (Consumer => Consumer);
      end loop All_Pairs;
   end Time_This;
   
   Stop  : Calendar.Time;
   Start : Calendar.Time := Calendar.Clock;
   
   use type Calendar.Time;
begin -- Prod_Cons
   Time_This;
   Stop := Calendar.Clock;
   Text_Io.Put_Line (Duration'Image (Stop - Start) );
end Prod_Cons;

Here are some typical outputs:

C:\ada>prod_cons
 18.340000000
 
C:\ada>prod_cons
 18.180000000
 
C:\ada>prod_cons
 19.170000000
 
C:\ada>prod_cons
 18.120000000
 
C:\ada>prod_cons
 19.660000000
 
C:\ada>prod_cons
 17.850000000
 
C:\ada>prod_cons
 17.630000000
 
C:\ada>prod_cons
 18.010000000

These give an average of 18.37 seconds per run. While not as good as 15
seconds, this is better than 30 seconds.

These figures are for GNAT 3.04a on a P120, 32MB, Win95. Built using

   gnatmake -O3 -gnatn prod_cons.adb

I conclude the 62-pair limitation is not related to amount of memory.

I would be interested in knowing how Jonas' version differs from mine.
-- 
Jeff Carter
Innovative Concepts, Inc.




  parent reply	other threads:[~1997-01-17  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-16  0:00 Ada versus Java - Tasking Jonas Nygren
1997-01-16  0:00 ` Brad Balfour
1997-01-25  0:00   ` Robert Dewar
1997-01-16  0:00 ` wiljan
1997-01-17  0:00 ` Jeff Carter [this message]
1997-01-19  0:00   ` David Taylor
1997-01-20  0:00     ` Jim Hopper
1997-01-20  0:00       ` Michael Paus
1997-01-21  0:00         ` Jim Hopper
1997-01-21  0:00           ` Larry Kilgallen
1997-01-21  0:00             ` jim hopper
1997-01-21  0:00     ` Dr. John B. Matthews
1997-01-23  0:00     ` Jeff Carter
1997-01-17  0:00 ` Steve Doiel
1997-01-18  0:00 ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-01-19  0:00   ` Robert A Duff
1997-01-19  0:00 ` Tom Moran
1997-01-19  0:00 ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-01-19  0:00   ` Larry Kilgallen
1997-01-20  0:00 ` Ada Tasking revisited (was: Re: Ada versus Java - Tasking) Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-01-20  0:00 ` Ada versus Java - Tasking Dale Pontius
1997-01-20  0:00 ` Jon S Anthony
1997-01-20  0:00 ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-01-21  0:00 ` Ole-Hjalmar Kristensen FOU.TD/DELAB
replies disabled

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