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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!border2.nntp.dca.giganews.com!nntp.giganews.com!backlog2.nntp.dca.giganews.com!nntp.sun.com!news.sun.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 01 Sep 2009 05:16:55 -0500 Newsgroups: comp.lang.ada Subject: Re: Ada Shootout program for K-Nucleotide (patches) References: <4a743343$0$32674$9b4e6d93@newsspool2.arcor-online.net> <0c18b36c-7af0-454c-8208-9b0416111a1f@w41g2000yqb.googlegroups.com> <4a758ce2$0$31338$9b4e6d93@newsspool4.arcor-online.net> <4a967b33$0$32671$9b4e6d93@newsspool2.arcor-online.net> From: Ole-Hjalmar Kristensen Organization: Sun Microsystems Date: 01 Sep 2009 12:16:54 +0200 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cache-Post-Path: news1nwk!unknown@khepri42.norway.sun.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-cuFXZlZlYUiuco59Ztp3X3WrlLIpCgfzFotX/PodWjL63rCWkRZ5tX214iyP/Nd0jA/o3SMaRTtmWYw!M1zYJwn1uQFHqXIAThDAsLmxKc9rqwXHvvbpCc81Xxxmh6NzhendMQuy X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Xref: g2news2.google.com comp.lang.ada:8095 Date: 2009-09-01T12:16:54+02:00 List-Id: Or you could use the Unix read system call and roll your own get_line function along these lines. It will read 1000000 lines of 60 characters line by line in about a second. with Interfaces.C_Streams; use Interfaces.C_Streams; with Ada.Text_Io; procedure Get_Line_Test is In_Buf : String(1..8192); for In_Buf'Alignment use 8192; First: Integer := In_Buf'last; Last: Integer := 0; N : Size_T := 1; function Read(Fd : Int; Buffer : Voids; Nbyte : Size_T) return Size_T; pragma Import(C,read); function Empty_Buffer return Boolean is begin return First > Last; end Empty_Buffer; pragma Inline(Empty_Buffer); function End_File return Boolean is begin return N <= 0; end End_File; pragma Inline(End_File); -- Get line from stdin, return "" if end of file function Get_Line return String is begin -- Get buffer from file if empty if Empty_buffer then N := Read(0,In_Buf(1)'Address, Size_T(In_Buf'Last)); First := 1; Last := Integer(N); end if; if Empty_Buffer then return ""; end if; -- Look for end of line and return it for I in First..Last loop if In_Buf(I) = Ascii.LF then declare Start : Integer := First; begin First := I + 1; return In_Buf(Start..I-1); end; end if; end loop; -- Did not find end of line, seek further declare Copy: string := In_Buf(First..Last); begin Last := 0; return Copy & Get_Line; end; end Get_Line; pragma Inline(Get_Line); begin while not End_File loop declare Line : String := Get_Line; begin -- Do something with line here null; end; end loop; end Get_Line_Test; astra06:~/ada/div-ada> uname -a SunOS astra06 5.10 Generic_137137-09 sun4u sparc SUNW,Sun-Fire-V440 astra06:~/ada/div-ada> ls -l x.txt -rw------- 1 ok145024 clustra 60000000 Sep 1 12:03 x.txt astra06:~/ada/div-ada> time ./get_line_test < x.txt 0.49u 0.09s 0:00.59 98.3% -- C++: The power, elegance and simplicity of a hand grenade.