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 X-Google-Thread: 103376,386228a37afe967f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-15 08:15:48 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Computer Language Shootout Date: 15 Jul 2003 08:15:48 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0307150715.4ba69f85@posting.google.com> References: NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1058282148 19937 127.0.0.1 (15 Jul 2003 15:15:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 15 Jul 2003 15:15:48 GMT Xref: archiver1.google.com comp.lang.ada:40289 Date: 2003-07-15T15:15:48+00:00 List-Id: Preben Randhol wrote in message news:... > Craig Carey wrote: > > > > The Ada entry to read numbers from a file was slow. > > > > The specs for the integer summing program are here: > > http://www.bagley.org/~doug/shootout/bench/sumcol/ > > I don't understand why your code is so complicated: Why not simply do: > > with Ada.Text_IO; use Ada.Text_IO; > > procedure sumcol is > Sum : Integer := 0; > Number : String (1 .. 128); > Last : Natural := 1; > begin > while not End_of_Line (Standard_Input) loop > Get_Line (Standard_Input, Number, Last => Last); > Sum := Sum + Integer'Value (Number (1 .. Last)); > end loop; > > Put_Line ("Sum: " & Integer'Image (Sum)); > end sumcol; > > And the spec above says that the line is only 128 characters wide, so > why do you allocate a string for 4096 ? It's not necessary to pass the object Standard_Input explicitly to End_Of_Line and Get_Line, because those operations are overloaded to read from standard input by default. You can also generate better code by declaring the Sum as Integer'Base instead of Integer; this turns off constraint checks. declare Sum : Integer'Base := 0; Line : String (1 .. 128); Last : Natural; begin while not End_Of_File loop Get_Line (Line, Last); Sum := Sum + Integer'Value (Line (Line'First .. Last)); end loop; ... end; You could also have used Integer_Text_IO.Get to read the value from the string buffer, instead of using Integer'Value. This would allow you to read multiple values from a single line (assuming that was required in this program). -Matt