From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7d2c8b4487ef2145 X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: Ada versus Java - Tasking Date: 1997/01/17 Message-ID: <32DFC320.41C67EA6@innocon.com>#1/1 X-Deja-AN: 210479065 references: <01bc03ee$594dc520$829d6482@joy.ericsson.se> content-type: text/plain; charset=us-ascii organization: DIGEX mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0 (X11; U; SunOS 4.1.3 sun4m) Date: 1997-01-17T00:00:00+00:00 List-Id: 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.