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!news.addix.net!border2.nntp.ams.giganews.com!nntp.giganews.com!fr.ip.ndsoftware.net!nntp-peering.plus.net!ptn-nntp-feeder03.plus.net!ptn-nntp-spool01.plus.net!ptn-nntp-reader03.plus.net!not-for-mail User-Agent: Microsoft-Entourage/10.1.6.040913.0 Date: Mon, 21 Mar 2005 01:42:26 +0000 Subject: Re: Ada bench From: "(see below)" Newsgroups: comp.lang.ada Message-ID: References: <87vf7n5njs.fsf@code-hal.de> <87u0n6mzas.fsf@code-hal.de> <2huslr9uto15$.nbw7z2uaceua.dlg@40tude.net> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Organization: Customer of PlusNet plc (http://www.plus.net) NNTP-Posting-Host: 114a1fce.ptn-nntp-reader03.plus.net X-Trace: DXC=NPL0=jfC0\?;Og:bYoaYU8igd3Y`7Rb;>@`8gV4CC7I7YTI\\_:3`?4NIh5>P<^QU6FE>R5bK459=fJ9 On 20/3/05 12:20 pm, in article 2huslr9uto15$.nbw7z2uaceua.dlg@40tude.net, "Dmitry A. Kazakov" wrote: > Pascal, could you also take care of the sum of column integers example? The > code creates a new string for each integer to be taken from! I did some experiments. - I used GNAT 3.3, MacOS X build 1650, my 500MHz iBook, MacOS X 10.3.8 - I had four variants, of which the last is best - All compiled with "gnatmake -O3 *.adb" - All run with "time ./sumcol? < iofile.txt" - All runs used iofile.txt, which contains 1000 repetitions of the content of Shootout's file, and therefore sums to 500_000 (verified for each run) - I calculated the cpu time (user+sys) for each of 3 runs and took the mean - For each program I present the source, the 3 cpu times, and the mean SumCol4 is not only the fastest, with a MEAN of 0m2.320s, I think it is the most accurate transcription of the Icon program, since Icon is an event-driven (~= exception-driven) string language. Unlike versions 1..3, SumCol4 outputs an initial space. If necessary, this could be removed using Trim. For comparison, the given C program, compiled with Shootout's flags, but run as above, gave: cpu 0m0.880s cpu 0m0.920s cpu 0m0.860s MEAN 0m0.830s If Ada and C performance scale similarly we should look for a figure, for SumCol4 on Shootout's hardware, of around 1.04s++ for N = 1000. Ada Results: -- SumCol1 with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure SumCol1 is Line : String (1 .. 128); Sum : Integer := 0; Len : Natural; begin while not End_Of_File loop Get_Line (Item => Line, Last => Len); Sum := Sum + Integer'Value (Line (1 .. Len)); end loop; Ada.Integer_Text_IO.Put (Item => Sum, Width => 0); New_Line; end SumCol1; time ./sumcol1 cpu 0m2.840s cpu 0m2.790s cpu 0m2.830s MEAN 0m2.820s ================ -- SumCol2 with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure SumCol2 is Num : Integer; Sum : Integer := 0; begin while not End_Of_File loop Get (Num); Sum := Sum + Num; end loop; Ada.Integer_Text_IO.Put (Item => Sum, Width => 0); New_Line; end SumCol2; time ./sumcol2 cpu 0m5.280s cpu 0m5.330s cpu 0m5.350s MEAN 0m5.320s ================ -- SumCol3 with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure SumCol3 is Num : Integer; Sum : Integer := 0; begin loop Get (Num); Sum := Sum + Num; end loop; exception when End_Error => Ada.Integer_Text_IO.Put (Item => Sum, Width => 0); New_Line; end SumCol3; time ./sumcol3 cpu 0m4.740s cpu 0m4.680s cpu 0m4.700s MEAN 0m4.710s ================ -- SumCol4 with Ada.Text_IO; use Ada.Text_IO; procedure SumCol4 is Line : String (1 .. 128); Sum : Integer := 0; Len : Natural; begin loop Get_Line (Item => Line, Last => Len); Sum := Sum + Integer'Value (Line (1 .. Len)); end loop; exception when End_Error => Put_Line (Integer'Image(Sum)); end SumCol4; time ./sumcol4 cpu 0m2.250s cpu 0m2.310s cpu 0m2.410s MEAN 0m2.320s ================ -- Bill