comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: String filtering
Date: Thu, 29 Sep 2005 16:05:26 +0200
Date: 2005-09-29T16:03:57+02:00	[thread overview]
Message-ID: <433bf44d$0$26212$9b4e6d93@newsread2.arcor-online.net> (raw)
In-Reply-To: <m3k6h1qzz8.fsf@rr.trudgett>

David Trudgett wrote:

> 
>>Good.  It makes the String and Unbounded_String versions practically
>>equivalent - probably both in CPU and memory use.
> 
> 
> Much of a muchness, I would guess. Profiling particular applications
> on particular compilers is the only way to tell for sure, though.

Got some figures. As expected, String is always faster than Unbounded_String.
Maybe surprisingly, Vector is somewhat faster than Unbounded_String
in all cases, provided inlining is used. Heap means the String objects
have been allocated using new.
Compiler is GCC 4.1 on GNU/Linux x86.

-O2 -gnatn -gnato:

 1. iteration, 10 chars, 1000000 runs.
Fixed:      2.084710000
Heap:       1.498224000
Unbounded:  7.608056000
Vector:     5.686385000
 2. iteration, 10000 chars, 1000 runs.
Fixed:      0.421747000
Heap:       0.477814000
Unbounded:  0.787875000
Vector:     0.515643000
 3. iteration, 1000000 chars, 10 runs.
Fixed:      0.560290000
Heap:       0.622039000
Unbounded:  1.137758000
Vector:     0.917281000

-O2 -gnato

 1. iteration, 10 chars, 1000000 runs.
Fixed:      1.730108000
Heap:       1.604875000
Unbounded:  7.659804000
Vector:     6.483596000
 2. iteration, 10000 chars, 1000 runs.
Fixed:      0.510872000
Heap:       0.566339000
Unbounded:  0.872703000
Vector:     1.044757000
 3. iteration, 1000000 chars, 10 runs.
Fixed:      0.650525000
Heap:       0.710203000
Unbounded:  1.213516000
Vector:     1.437887000


The Vector function uses Vec_String in place of Unbounded_String,
where subtype Vec_String is Character_Vectors.Vector:


   function Strip_Non_Alphanumeric
     (Str: in Vec_String) return Vec_String
   is
      use Character_Vectors, Ada.Containers;

      Dest_Char: Index_Subtype'Base := 0;
      New_Str: Vec_String;
      Dest_Size: constant Count_Type := Length(Str);

   begin
      if Dest_Size > 0 then
         New_Str := To_Vector(Dest_Size);
         for Src_Char in 1 .. Last_Index(Str) loop
            if Is_In(Element(Str, Src_Char), Alpha_Num_Space_Set) then
               Dest_Char := Dest_Char + 1;
               Replace_Element
                 (New_Str, Dest_Char, Element(Str, Src_Char));
            end if;
         end loop;
      else
         null;
      end if;
      return New_Str;
   end Strip_Non_Alphanumeric;



  reply	other threads:[~2005-09-29 14:05 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-27  6:27 String filtering David Trudgett
2005-09-27  7:38 ` Jacob Sparre Andersen
2005-09-27  9:13   ` David Trudgett
2005-09-27  9:49     ` Dmitry A. Kazakov
2005-09-27 11:01       ` Martin Dowie
2005-09-27 11:12         ` Martin Dowie
2005-09-27 12:54           ` Dmitry A. Kazakov
2005-09-27 13:42             ` Martin Dowie
2005-09-27 14:24               ` Dmitry A. Kazakov
2005-09-28  0:06                 ` David Trudgett
2005-09-28  8:15                   ` Dmitry A. Kazakov
2005-09-28 10:39                     ` David Trudgett
2005-09-28 20:55                       ` Simon Wright
2005-09-28 21:53                         ` Martin Dowie
2005-09-28  9:08                   ` Jacob Sparre Andersen
2005-09-28  9:54                     ` David Trudgett
2005-09-29 14:05                       ` Georg Bauhaus [this message]
2005-10-01 19:02                         ` tmoran
2005-10-02  6:38                           ` David Trudgett
2005-10-02 14:11                             ` Martin Dowie
2005-10-02 22:40                               ` David Trudgett
2005-10-03  5:56                                 ` Martin Dowie
2005-10-03 10:33                           ` Georg Bauhaus
2005-09-28 18:21                   ` Jeffrey R. Carter
2005-09-28 21:00                   ` Simon Wright
2005-09-27 11:22         ` David Trudgett
2005-09-27 11:15       ` David Trudgett
2005-09-27 13:21         ` Dmitry A. Kazakov
2005-09-27 13:43           ` Martin Dowie
2005-09-28  0:51           ` David Trudgett
2005-09-28 12:02             ` Dmitry A. Kazakov
2005-09-28 13:25             ` Marc A. Criley
2005-09-29 22:42           ` Randy Brukardt
2005-09-30 17:54             ` Robert A Duff
2005-10-02  6:57               ` Steve Whalen
2005-10-02 14:14                 ` Martin Dowie
2005-10-03  1:21                 ` Robert A Duff
2005-10-03  7:44                   ` Jacob Sparre Andersen
2005-10-03  8:56                     ` Dmitry A. Kazakov
2005-10-03  9:25                       ` Jean-Pierre Rosen
2005-10-03 20:17                         ` Ada Notation Jeffrey R. Carter
2005-10-03 20:41                           ` Georg Bauhaus
2005-10-05 17:16                             ` Andre
2005-10-05 18:23                               ` Ludovic Brenta
2005-10-05 18:24                               ` Jeffrey R. Carter
2005-10-04 15:13                           ` brian.b.mcguinness
2005-10-04 17:00                     ` String filtering Robert A Duff
2005-10-05  8:19                       ` Jean-Pierre Rosen
2005-10-05 11:25                         ` Robert A Duff
2005-10-04 19:47                     ` Björn Persson
2005-10-05 14:14                       ` Dmitry A. Kazakov
2005-10-03 10:06                   ` Steve Whalen
2005-10-03 17:43                   ` tmoran
2005-10-03 17:59                     ` Robert A Duff
2005-10-05 23:04                       ` Randy Brukardt
2005-09-27 13:52         ` Jacob Sparre Andersen
2005-09-28  1:01           ` David Trudgett
2005-09-28  1:50             ` David Trudgett
2005-09-27 14:08         ` Georg Bauhaus
2005-09-27 14:09         ` Marc A. Criley
2005-09-28  1:09           ` David Trudgett
2005-09-28 21:09           ` Simon Wright
2005-09-27 17:59         ` tmoran
2005-09-28  1:20           ` David Trudgett
2005-09-27 17:47     ` Jeffrey R. Carter
2005-09-28  1:29       ` David Trudgett
2005-09-28 18:32         ` Jeffrey R. Carter
2005-09-27  7:41 ` tmoran
2005-09-27  9:17   ` David Trudgett
2005-09-28  1:54 ` Steve
2005-09-28  2:20   ` David Trudgett
replies disabled

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