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-11 05:50:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!news.tele.dk!news.tele.dk!small.news.tele.dk!uninett.no!ntnu.no!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: Computer Language Shootout Date: Fri, 11 Jul 2003 12:50:36 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: NNTP-Posting-Host: kiuk0152.chembio.ntnu.no X-Trace: tyfon.itea.ntnu.no 1057927836 5331 129.241.83.78 (11 Jul 2003 12:50:36 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Fri, 11 Jul 2003 12:50:36 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:40191 Date: 2003-07-11T12:50:36+00:00 List-Id: 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 ? > I argue here that the Gcc sumcol entry should be rejected. The C > programmers assumed that the file's lines were known, thus they > knew there was only 100 lines. Speed is not important with 100 > lines files, but losing a patch of the competition due to buggy > code from C programmer might easily be more important. I cannot see that they used this assumption for the code here: http://dada.perl.it/shootout/sumcol.gcc.html > That says programs "can assume" that each line has no more than 128 > characters. Thus checking can be omitted and a crash is OK. A quite > different wording was used in the specs, for lines containing 2 > integers. > > The specs author, Mr Bagley wrote that the programs "should" read > integers "line by line". The C programmers in fact were never told > whether to use the first integer or the 2nd (if there are two or > more). Also they were required to read an integer when there was > none, which suggests error checking but their C code has none. I find the spec a bit unclear about this. As I understand it and this seems to be the way most implementations are done, is that one can expect one integer per line. -- Ada95 is good for you. http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php