comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: Large strings in ADA
Date: 2000/04/17
Date: 2000-04-17T00:00:00+00:00	[thread overview]
Message-ID: <I0vK4.1823$lM4.428284@news.pacbell.net> (raw)
In-Reply-To: dale-8445E2.08102617042000@news.rmit.edu.au

>Perhaps you should try duplicating the -exact- C semantics. Presumably
>you have a -very- large char buffer into which the items are copied.

  If the original is in C, it must have something like
     char Msg[2500000];  // 2.5 MB
so the straightforward Ada equivalent would be
     Msg : String(1 .. 2_500_000);  -- 2.5 MB

  If Appends are about K characters that will be 2.5E6/K Appends.
If Append is done with strcat, searching for the terminating null
instead of by maintaining an index, the total amount of scanning
would be 0+K+2K+3K ...  25.E6 or nearly K*(2.5E6/K)**2/2 or
3E12/K.  If the machine can scan for a null at a 10**9 byte/sec,
and that's the only thing that takes any time at all,
then K, the average string length, must be at least 3,000.

  Assuming the average string length is substantially less than
3K characters, we see that the C version must be using an index.
In that case the simple Ada equivalent would be something like:

   Msg : String(1 .. 2_500_000);
   Last : Natural := 0;

   procedure Append_To_Msg (Str : in String;
                            Max_Len : in Natural;
                            Message : in out String;
                            Last : in out Natural) is
     New_Stuff : constant String
       := " " & Natural'Image(Max_Len) & " " & Str;
   begin
     Message(Last+1 .. Last+New_Stuff'length) := New_Stuff;
     Last := Last + New_Stuff'length;
   end Add_To_Message;

I made that change, modified the given program to compilable Ada,
changed the loop from 1 .. 1600 to 1 .. 2_500_000/(32+4)
(each append stores 36 characters), compiled with gnat 3.12p NT
with -O2 -gnato, and the result runs on a Pentium 200 in 0.8 second.




  reply	other threads:[~2000-04-17  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-16  0:00 Large strings in ADA Johan Groth
2000-04-16  0:00 ` David Starner
2000-04-17  0:00 ` Robert Dewar
2000-04-17  0:00 ` Dale Stanbrough
2000-04-17  0:00   ` tmoran [this message]
2000-04-17  0:00     ` Johan Groth
2000-04-17  0:00       ` tmoran
2000-04-18  0:00         ` tmoran
2000-04-22  0:00           ` Johan Groth
2000-04-17  0:00       ` Florian Weimer
2000-04-17  0:00       ` Robert Dewar
2000-04-17  0:00         ` David Starner
2000-04-17  0:00 ` Florian Weimer
2000-04-17  0:00 ` Robert Dewar
replies disabled

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