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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f802583e5c84fa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Thu, 29 Sep 2005 16:05:26 +0200 From: Georg Bauhaus User-Agent: Debian Thunderbird 1.0.2 (X11/20050817) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: String filtering References: <1j92wa9843ylq.16j89wuqatbaj$.dlg@40tude.net> <433924a2$1_1@glkas0286.greenlnk.net> <43392732$1_1@glkas0286.greenlnk.net> <1jd30obyohnp6$.41tz3funikly.dlg@40tude.net> <43394a3e$1_1@glkas0286.greenlnk.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <433bf44d$0$26212$9b4e6d93@newsread2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Sep 2005 16:03:57 MEST NNTP-Posting-Host: 3eccdf34.newsread2.arcor-online.net X-Trace: DXC=AGiWEL^K^ 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;