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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8de7eedad50552f1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 22 Mar 2005 06:22:22 -0600 Date: Tue, 22 Mar 2005 07:22:54 -0500 From: Jeff C User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada bench : count words References: <87vf7n5njs.fsf@code-hal.de> <423f5813$0$9224$9b4e6d93@newsread4.arcor-online.net> <18arnvu705ly4$.1wz6ybz1jt70y$.dlg@40tude.net> In-Reply-To: <18arnvu705ly4$.1wz6ybz1jt70y$.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.147.74.171 X-Trace: sv3-rep0PX7atdEsRadtdN9lzaT7lsB3ulkNjtd2IzqjdQ+wzaEbO4kBDHi+iJlAB1W8W8d8+AxJUi0x2Mw!6fhhiNsZMLZE44ImlpjqCLDqole6R28GBpkOeTGAwhIPI0knITUIQ46BZz3zwg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net 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.32 Xref: g2news1.google.com comp.lang.ada:9724 Date: 2005-03-22T07:22:54-05:00 List-Id: Dmitry A. Kazakov wrote: > On Tue, 22 Mar 2005 01:16:09 +0000, Marius Amado Alves wrote: > > >>I took a shot at the count-words benchmark, a program to count lines, >>words and characters. The Ada program currently published there is >>broken. My program is correct and portable but: >> >>- the speed is circa 1/3 of the GCC C version >> >>- it fails to comply with the requirement that the input be taken from >>standard input. To implement buffering, I have resorted to >>Ada.Direct_IO, which I think cannot apply to standard input. > > > Is Text_IO that bad? It can be. It does a few things that real programs often do not need to do (counting pages) and may not do buffering that is optimal for the job here. The problem is of course that it is a requirement to read from standard input and if I were running the website I would reject a program that does not. Perhaps this could be done by using ada.text_io.text_streams to get access to a stream based on standard input and then use the "Read" procedure (v.s. 'read attribute) to get 4k blocks of data (recommended chunking size from problem definition). The Read procedure uses an "Item" and "Last" approach so you can look for Last to see how much you actually read. Note since Ada 95 came out I hardly ever use direct_io anymore because even problems that seem to line up well with direct IO over time degrade as file formats change. I tend to jump (perhaps to soon) to ada.streams.stream_io approaches and or approaches like getting access to text_io streams. Note in this case I am not saying that the text_io stream approach will be faster..I dont really know..But at least it can be made compliant with the requirements of the test. with Text_IO; with Ada.Text_IO.Text_Streams; use Ada.Text_IO.Text_Streams; use Text_IO; with Ada.Streams; use Ada.Streams; procedure stre_test is S : Stream_Access := Stream(Standard_Input); Data : Stream_Element_Array(1 .. 10); Last : Stream_Element_Offset; begin Read(S.all, Data, Last); Text_IO.Put_Line(Stream_Element_Offset'image(Last)); end stre_test;