comp.lang.ada
 help / color / mirror / Atom feed
From: dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner)
Subject: Re: Large strings in ADA
Date: 2000/04/16
Date: 2000-04-16T00:00:00+00:00	[thread overview]
Message-ID: <8ddcko$a2g1@news.cis.okstate.edu> (raw)
In-Reply-To: 38FA3003.A38D7B51@xpress.se

On Sun, 16 Apr 2000 23:26:27 +0200, Johan Groth <jgroth@xpress.se> wrote:
>Hello,
>I'm trying to write a program that converts a couple of types to strings
>and are concatenated into one large string that is at the moment a
>unbounded_string but when the string gets about 50KB big it takes longer
>and longer to append to it.
>The code looks like below. I need to concatenate about 2.5MB of data.
>What is the fasted way to do that in ADA? Just for comparison a similar
>program in C takes about one second.

Then it's not similar. C doesn't have Unbounded_Strings and 'Image attribute,
so I doubt the two programs are all that similar. At the worst, why 
didn't/don't you transliterate that C into Ada? It won't be nice, pretty or 
friendly, but it will probably be as fast as the C version (with checks
turned off.) This below isn't similar to any C program I can concieve of -
C just won't let you write at this level.

>Can anyone help me?
>
>TIA,
>Johan
>
>procedure Main is
>   type String32 is
>     record
>	Info : String(1..32) := (others => ' ');
>	Len : Natural range 0 .. 32 := 0;
>     end record;
>
>   Str : String32;
>   No : Basic_Integer;
>   Flt : Basic_Float;
>   Msg : Unbounded_String := Null_Unbounded_String;
>   Last : Natural;
>
>   procedure Append_To_Msg (Str : in String;
>                            Max_Len : in Natural;
>                            Message : in out Asu.Unbounded_String;
>                            Last : in out Natural) is
>   begin
>      Append(Message, " ");
>      Append(Message, Natural'Image(Max_Len));
>      Append(Message, " ");
>      Append(Message, Str);
>      Last := Asu.Length (Message);

It probably really hurts to count the length of the string
over and over. In fact, this is where I would bet a lot of time
is going. Why don't you try gprof (for GNAT) or a profiler
for whatever Ada compiler you're using and see where the times
being spent?

>   end Add_To_Message;
>
>begin
>   Str.info(1..6) := "hejsan";
>   Str.Len := 6;
>   No := 10;
>   Flt := 5.5;
>   for I in 1 .. 1600 loop
>      Append_To_Msg(Str.Info, Basic_Natural(Str.Len), Msg, Last);

Why don't you pass Basic_Natural (Str.Len)'Image in? If you do so,
most compilers will do the conversion only once, instead of 1600
times.

Also, you don't mention what compiler's you're comparing, running
on what systems, with what switchs, which can make a big difference.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




  reply	other threads:[~2000-04-16  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 [this message]
2000-04-17  0:00 ` Robert Dewar
2000-04-17  0:00 ` Dale Stanbrough
2000-04-17  0:00   ` tmoran
2000-04-17  0:00     ` Johan Groth
2000-04-17  0:00       ` Robert Dewar
2000-04-17  0:00         ` David Starner
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 ` 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