From: nickroberts@ukf.net (Nick Roberts)
Subject: Re: How to speed up stream & record handling?
Date: Sun, 24 Feb 2002 03:23:01 GMT
Date: 2002-02-24T03:23:01+00:00 [thread overview]
Message-ID: <3c782af9.8462803@news.cis.dfn.de> (raw)
In-Reply-To: e7ebd224.0202210437.1c7d0fbf@posting.google.com
On 21 Feb 2002 04:37:57 -0800, karlran1234@yahoo.com (Karl Ran) strongly
typed:
>Hello,
>I've a problem getting a reasonable IO preformance from an Ada
>program (source is attached)
>
>The environment looks like this:
>OS: linux-2.4.16
>CPU: Intel P3/700 MHz / BX chipset
>compiler: gnat-3.14p
>
>The program reads a packet of data (200 bytes) and converts the
>header(2 bytes) to match the architecture. It will do it 100000 times.
>...
My suggestion (you may not like it!) is: (a) if possible, ensure the
NIC/DMA dumps the data into a useful piece of memory (i.e. shared); (b)
preferably, use assembly.
>It's too slow for the target application.
Which is, please?
>I know the the PC achitecture is known for their bad IO performance,
>but this 2.4 MBytes/s seems not be related to the PC-IO-bottleneck...
I'm sorry but this is a jaw-dropper. Speak not of that which thou wot not
of, child.
My suggestion for improvements in your Ada code follows.
with Ada.Text_IO;
with Ada.Streams.Stream_IO;
procedure Slow_Ada is
type Machine_Architecture is (Little_Endian, Big_Endian);
Architecture: constant Machine_Architecture := Little_Endian; -- IA
subtype Must_Be_True is Boolean range True..True;
Check_Element_Size: constant Must_Be_True :=
Ada.Streams.Stream_Element'Size = 8;
subtype Data_Array is Ada.Streams.Stream_Element_Array(1..200);
procedure Adjust_Data (Data: in out Data_Array) is
Temp: Ada.Streams.Stream_Element; -- assuming this is a byte
begin
case Architecture is
when Little_Endian =>
Temp := Data(199);
Data(199) := Data(200);
Data(200) := Temp;
when Big_Endian =>
null;
end case;
end Adjust_Data;
pragma Inline(Adjust_Data);
Item: Data_Array;
Last: Ada.Streams.Stream_Element_Offset;
File: Ada.Streams.Stream_IO.File_Type;
begin
Ada.Streams.Stream_IO.Open
(Name => "/dev/zero", --use any big file you like (20 MByte)
File => File,
Mode => Ada.Streams.Stream_IO.In_File);
Put("Starting...");
for I in 1 .. 100000 loop
--- test for end of file?
Read(File,Item,Last);
-- test Last for /= 200?
Adjust_Data(Item);
-- do something with the data?
end loop;
Put_Line("Done.");
Ada.Streams.Stream_IO.Close (File);
end Slow_Ada;
If a stream element isn't a byte, you'll need to adjust Adjust_Data (and
remove or change Check_Element_Size). At this (low) level, this sort of
twiddling will always be necessary.
(Also, note how my code does the job with the minimum of 'fuss'.)
Hope this helps.
--
Nick Roberts
prev parent reply other threads:[~2002-02-24 3:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-21 12:37 How to speed up stream & record handling? Karl Ran
2002-02-21 14:17 ` Martin Dowie
2002-02-21 17:34 ` Jeffrey Carter
2002-02-21 20:25 ` Florian Weimer
2002-02-21 23:59 ` tmoran
2002-02-22 13:31 ` Karl Ran
2002-02-22 20:25 ` tmoran
2002-02-24 3:23 ` Nick Roberts [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox