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-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!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 13:49:26 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Ada bench : count words References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Tue, 22 Mar 2005 13:49:26 -0600 NNTP-Posting-Host: 67.161.24.234 X-Trace: sv3-2DIhdQCWFANdBVK7hprzid2UNBC9QQjQeCFzVOtjS5OdKpu0b53ssXG3XBfajbAiqQ4nGTcw1MAgKW1!jUH9OIN0qnCU333WIq4047g4DOYz8h0gRZQRlJq5MrpyFdMejmaQZ5JNvWnK2A== 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:9749 Date: 2005-03-22T13:49:26-06:00 List-Id: > - 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, 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); T0, T1 : Ada.Calendar.Time; begin T0 := Ada.Calendar.Clock; 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; 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;