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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.125.72 with SMTP id x8mr1251290qar.5.1380682721073; Tue, 01 Oct 2013 19:58:41 -0700 (PDT) X-Received: by 10.49.51.197 with SMTP id m5mr315qeo.5.1380682721035; Tue, 01 Oct 2013 19:58:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!q9no833019qas.0!news-out.google.com!9ni1076qaf.0!nntp.google.com!q9no833013qas.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 1 Oct 2013 19:58:40 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2607:fe50:0:8514:f66d:4ff:fed0:32ee; posting-account=2ZF-4AoAAACjyRiHABaMHHY6KlpUj2jN NNTP-Posting-Host: 2607:fe50:0:8514:f66d:4ff:fed0:32ee User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8aca502c-bba8-4af5-9192-459c15fe048b@googlegroups.com> Subject: Optimizing Ada From: kennethesills@gmail.com Injection-Date: Wed, 02 Oct 2013 02:58:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:17366 Date: 2013-10-01T19:58:40-07:00 List-Id: tl;dr Just started using Ada. Two code samples are on the bottom, one is Ad= a, one is Rust. The functions simply return a map of words and how often th= ey are used in a given string. The Ada one is far slower even though almost= all other test cases are faster, and I wanted to know how I might be able = to optimize it a bit. And for those who want a bit more detail: I decided to give Ada a spin recently and started working on Martyr's Mega = Project List to learn the language. I use this to judge the languages perfo= rmance, readability, etc. And have implemented in quite a few languages. I've also recently been experimenting with Rust, which (if you don't alread= y know) is another safety-oriented language, but far newer and some bit mor= e C++-ish. So simultaneously, I've been working on the Rust version. So far, Ada has been more verbose (by far), but the tooling (compiler and G= PS), but also comes out easier for me to read looking back at the code. The= only real snags I've hit with Ada is trouble with finding documentation on= the standard library. The performance Ada has been putting out is actually very impressive, as we= ll. Consistently demolishing Rust's performance, and sometimes even C++: Count_Vowels: Rust =3D> 19 ns Ada =3D> .5 ns (-O2 actually optimizes the benchmark away entirely). Reverse String: Rust =3D> 111 ns Ada =3D> 29.3 ns Is Palindrome: Rust =3D> 119 ns (Rust version is actually case sensitive, so technically "= broken".) Ada =3D> 56.1 ns To Pig Latin (Best/Worst/Middle): Rust =3D> 91 - 141 - 140 ns Ada =3D> 34 - 44 - 35 ns I just finished implementing the Count Word Use function (pretty self-expla= natory - makes a map of how often words are used) for both languages, and e= xpected the same result in terms of performance. However, the actuals were = completely opposite to my expectations: Count Word Use: Rust =3D> 2763 ns (Again, case sensitive, so technically it's "broken".) Ada =3D> 7436.9 ns So I was just wondering if anyone could help me optimize my Ada code a bit,= as well as tell me how I'm doing in terms of general code style and idioma= tic code writing. Here are the two code samples: Ada Code : http://pastebin.com/vDbdXCYD (a quotation mark messed up highlig= hting near bottom) Rust Code: http://pastebin.com/1ZVL7Pjf Thank you and have a great day.