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!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!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: Date: Tue, 22 Mar 2005 22:51:27 +0100 Message-ID: <1cssfg6rke0bv$.1ou69sudrkdgz$.dlg@40tude.net> NNTP-Posting-Date: 22 Mar 2005 22:51:25 MET NNTP-Posting-Host: 97b39f8d.newsread4.arcor-online.net X-Trace: DXC=VCVcFboVTRJL0\Y_Wg[Z[N:ejgIfPPldDjW\KbG]kaMHdbobRQ:W=WBM3eMe_?AHeLWRXZ37ga[7Jeh9Z=IkP^1DR2Tfa\IXdEF X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9759 Date: 2005-03-22T22:51:25+01:00 List-Id: On Tue, 22 Mar 2005 13:49:26 -0600, tmoran@acm.org wrote: >> - the speed is circa 1/3 of the GCC C version >> ... >> The complete program follows. > > I missed the original post with the URL of the benchmark, I saw two: http://shootout.alioth.debian.org/great/benchmark.php?test=wc&lang=all&sort=fullcpu, and http://dada.perl.it/shootout/wc.html > but this > appears on my machine to be about 5x as fast (gnatmake -gnato -O2): > > with Ada.Calendar, > Ada.Streams, > Ada.Streams.Stream_IO, > Ada.Text_IO, > Ada.Text_IO.Text_Streams; > procedure Cw is > use Ada.Streams; > use type Ada.Calendar.Time; > Stream : Ada.Text_IO.Text_Streams.Stream_Access; > Buffer : Stream_Element_Array(1 .. 4096); > Last : Stream_Element_Offset; > Lines, Words, Total : Natural := 0; > In_Word : Boolean := False; > LF : constant Stream_Element := Character'pos(Ascii.LF); > CR : constant Stream_Element := Character'pos(Ascii.CR); > EOF_Char: constant Stream_Element := 16#1A#; > Is_Separator: constant array (Stream_Element) of Boolean > := (0 .. 32 | 127 .. 159 => True, others => False); It seems (from the description) that the separators are HT, SP, LF. Everything else is a "letter". > T0, T1 : Ada.Calendar.Time; > begin > > T0 := Ada.Calendar.Clock; No, they count load time as the run-time to be run as: for i in 1 2 3 4 5 6 7 8 9 10; do time command done So better link all static! (:-)) > Stream := Ada.Text_IO.Text_Streams.Stream(Ada.Text_IO.Current_Input); > Through_File: > loop > Ada.Streams.Read(Ada.Streams.Root_Stream_Type'Class(Stream.all), > Buffer, Last); > for I in 1 .. Last loop > exit Through_File when Buffer(I) = EOF_Char; > Total := Total + 1; > if Is_Separator(Buffer(I)) then > In_Word := False; > if Buffer(I) = LF then -- LF counts toward Total and toward Lines > Lines := Lines + 1; > elsif Buffer(I) = CR then -- don't count CR as content or as a line > Total := Total-1; Remove this, CR is a letter! (:-)) > end if; > else > if not In_Word then > Words := Words + 1; > In_Word := True; > end if; > end if; > end loop; > exit Through_File when Last < Buffer'Last; > end loop Through_File; > > T1 := Ada.Calendar.Clock; > > Ada.Text_IO.Put_Line(Natural'Image(Lines) > & Natural'Image(Words) > & Natural'Image(Total)); > Ada.Text_IO.Put_Line("took" & Duration'Image(T1 - T0)); > end Cw; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de