comp.lang.ada
 help / color / mirror / Atom feed
From: kennethesills@gmail.com
Subject: Optimizing Ada
Date: Tue, 1 Oct 2013 19:58:40 -0700 (PDT)
Date: 2013-10-01T19:58:40-07:00	[thread overview]
Message-ID: <8aca502c-bba8-4af5-9192-459c15fe048b@googlegroups.com> (raw)

tl;dr Just started using Ada. Two code samples are on the bottom, one is Ada, one is Rust. The functions simply return a map of words and how often they 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 performance, readability, etc. And have implemented in quite a few languages.

I've also recently been experimenting with Rust, which (if you don't already know) is another safety-oriented language, but far newer and some bit more 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 GPS), 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 well. Consistently demolishing Rust's performance, and sometimes even C++:

Count_Vowels:
Rust => 19 ns
Ada  => .5 ns (-O2 actually optimizes the benchmark away entirely).

Reverse String:
Rust => 111 ns
Ada  => 29.3 ns

Is Palindrome:
Rust => 119 ns (Rust version is actually case sensitive, so technically "broken".)
Ada  => 56.1 ns

To Pig Latin (Best/Worst/Middle):
Rust => 91 - 141 - 140 ns
Ada  => 34 - 44  - 35 ns


I just finished implementing the Count Word Use function (pretty self-explanatory - makes a map of how often words are used) for both languages, and expected the same result in terms of performance. However, the actuals were completely opposite to my expectations:

Count Word Use:
Rust => 2763 ns (Again, case sensitive, so technically it's "broken".)
Ada  => 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 idiomatic code writing.

Here are the two code samples:

Ada Code : http://pastebin.com/vDbdXCYD (a quotation mark messed up highlighting near bottom)
Rust Code: http://pastebin.com/1ZVL7Pjf

Thank you and have a great day.

             reply	other threads:[~2013-10-02  2:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02  2:58 kennethesills [this message]
2013-10-02  3:47 ` Optimizing Ada Jeffrey Carter
2013-10-02  3:53   ` kennethesills
2013-10-02  4:13     ` Jeffrey Carter
2013-10-02  4:24       ` kennethesills
2013-10-02  8:11         ` Jacob Sparre Andersen
2013-10-02 10:32           ` Marius Amado-Alves
2013-10-02 14:24           ` kennethesills
2013-10-02 16:41         ` Jeffrey Carter
2013-10-02 18:58       ` John B. Matthews
2013-10-02  7:01 ` Egil H H
2013-10-02  7:16 ` Simon Wright
2013-10-02 14:43   ` kennethesills
2013-10-02 10:24 ` Marius Amado-Alves
2013-10-02 14:29   ` kennethesills
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox