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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!feeder.xsnews.nl!195.14.215.231.MISMATCH!news.netcologne.de!newsfeed-fusi.netcologne.de!151.189.20.20.MISMATCH!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada bench : count words Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <87vf7n5njs.fsf@code-hal.de> <423f5813$0$9224$9b4e6d93@newsread4.arcor-online.net> Date: Tue, 22 Mar 2005 23:27:25 +0100 Message-ID: <1j5jfikipztuc.jx5n2zhbg2np$.dlg@40tude.net> NNTP-Posting-Date: 22 Mar 2005 23:27:22 MET NNTP-Posting-Host: fde648ac.newsread4.arcor-online.net X-Trace: DXC=:0cj;fEBM6Tadj;CH1=J1P:ejgIfPPldTjW\KbG]kaMXdbobRQ:W=WRXG0g2bURJ On Tue, 22 Mar 2005 01:16:09 +0000, Marius Amado Alves wrote: Here is a FSM/OS_Lib variant, a shameless one, I must admit. Anyway it narrowly beats: http://dada.perl.it/shootout/wc.gcc.html on my FC3 machine. But of course it has no chance against: http://shootout.alioth.debian.org/great/benchmark.php?test=wc&lang=gcc&id=0&sort=fullcpu, which uses even dirtier tricks than me! (:-)) ---------------------------------------------------- with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Ada.Text_IO; use Ada.Text_IO; with GNAT.OS_Lib; use GNAT.OS_Lib; procedure Ada_WC is subtype Buffer_Index is Integer range 1..4099; type File_Buffer is array (Buffer_Index) of aliased Character; Buffer : File_Buffer; Index : Buffer_Index := Buffer_Index'First; Last : Integer := Buffer_Index'First; Lines : Natural := 0; Words : Natural := 0; Total : Natural := 0; begin <> if Index < Last then -- This "if" should be a subprogram, Index := Index + 1; -- but I don't trust GNAT! else Last := Read (Standin, Buffer (1)'Address, 4098); -- 4K! to read if Last = 0 then goto Done; end if; Total := Total + Last; Index := Buffer_Index'First; end if; case Buffer (Index) is when ' ' | HT => goto Blank; when LF => Lines := Lines + 1; goto Blank; when others => Words := Words + 1; end case; <> if Index < Last then Index := Index + 1; else Last := Read (Standin, Buffer (1)'Address, 4098); if Last = 0 then goto Done; end if; Total := Total + Last; Index := Buffer_Index'First; end if; case Buffer (Index) is when ' ' | HT => goto Blank; when LF => Lines := Lines + 1; goto Blank; when others => goto Word; end case; <> Put_Line ( Natural'Image (Lines) & Natural'Image (Words) & Natural'Image (Total) ); end Ada_WC; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de