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=0.7 required=5.0 tests=BAYES_00,MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,95c23095599677a5,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-21 16:22:11 PST Path: supernews.google.com!sn-xit-03!supernews.com!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: dvdeug@my-deja.com Newsgroups: comp.lang.ada Subject: Optimization Question Date: Mon, 22 Jan 2001 00:05:21 GMT Organization: Deja.com Message-ID: <94ftfu$b59$1@nnrp1.deja.com> NNTP-Posting-Host: 139.78.80.137 X-Article-Creation-Date: Mon Jan 22 00:05:21 2001 GMT X-Http-User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.0 i686; Nav) X-Http-Proxy: 1.0 x65.deja.com:80 (Squid/1.1.22) for client 139.78.80.137 X-MyDeja-Info: XMYDJUIDdvdeug Xref: supernews.google.com comp.lang.ada:4284 Date: 2001-01-22T00:05:21+00:00 List-Id: I'm trying to write a program similar to the Unix utility strings, as my copy of strings refuses to run a 17GB file. It seems to work, but it's about 10x slower than strings, and rough calculations puts running time on that 17GB file at 10 hours. I'm running the woody Debian version of GNAT (3.13) on i686-linux-gnu, and I compiled the program with gnatmake -g -gnatwa -gnatpn -Wall -W -O3 strings.adb. Is there anything I've missed that speed this program a lot? (It's been run through gcov, so the numbers up front are execution counts.) with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Sequential_IO; with Ada.Command_Line; use Ada.Command_Line; with Ada.Text_IO; 2 procedure Strings is 1 type Byte is mod 2 ** 8; package Byte_IO is new Ada.Sequential_IO (Byte); use Byte_IO; 56710 function String_Charp (A : Character) return Boolean is begin 56710 return Is_ISO_646 (A) and then (Is_Graphic (A) or else A = HT or else A = LF or else A = CR); end String_Charp; pragma Inline (String_Charp); 1 Binary_File : File_Type; 1 Letter_Buffer : String (1 .. 4); subtype Buffer_Size is Integer range 0 .. 4; 1 Letters_Found : Buffer_Size := 0; 1 Current_Char : Byte; 1 Seperating_String : constant String := (LF, NUL); begin 1 if Argument_Count /= 1 then ###### Set_Exit_Status (1); ###### Ada.Text_IO.Put ("One file name only!"); ###### return; end if; 1 Open (Binary_File, In_File, Argument(1)); 56711 loop 56711 Read (Binary_File, Current_Char); 56710 if String_Charp (Character'Val (Current_Char)) then 29610 if Letters_Found < 4 then 8453 Letters_Found := Letters_Found + 1; 8453 Letter_Buffer (Letters_Found) := Character'Val (Current_Char); 8453 if Letters_Found = 4 then 916 Ada.Text_IO.Put (Letter_Buffer); end if; else 21157 Ada.Text_IO.Put (Character'Val (Current_Char)); end if; else 27100 if Letters_Found = 4 then 916 Ada.Text_IO.Put (Seperating_String); end if; 27100 Letters_Found := 0; end if; end loop; ###### Ada.Text_IO.Put ("Invalid end!"); ###### Set_Exit_Status (2); exception 1 when End_Error => 1 Close (Binary_File); ###### when others => ###### raise; end Strings; -- David Starner - dstarner98@aasaa.ofe.org Sent via Deja.com http://www.deja.com/