Ada vs Java vs C#

Ada vs Java vs C#

Performance measurement sample

I prepare small and simple problem just for measuring real life performance of different run-time environments and corresponding languages.  For now I implemented three versions: Ada, C# and Java.

The code use: object instance creation, parameter passing, returning a value from function, simple string manipulation and simple arithmetic operation. Sample was running for 50 million times in the loop. Each measurement represent one full execution of the main program.  My environment was:  Windows 10 64bit, Intel Core i7 2630QM processor and 8 GB RAM.

I am not sure how is that even possible, but Java was 3 times faster then C# and 10 times faster then Ada, it’s a clear winner here !

Looks like compiled language (Ada) lost this battle with highly optimized virtual machines, especially with Java HotSpot VM, which also compile some parts of java code to machine code too.

Measurements in seconds

2016-08-14 23_43_47-Ada_vs_Java_vs_C#.odt - LibreOffice Writer(Lower is better)

Ada code

GPS 2016 (20160515) hosted on i686-pc-mingw32
GNAT GPL 2016 (20160515-49)
(c) 2001-2016 AdaCore

Compiled with full optimizations, without debugging:

gprbuild -d -PH:\Ada\SOURCE\Codesample1\codesample1.gpr
gcc -c -gnat12 -O3 -gnatp main.adb
gcc -c -gnat12 -O3 -gnatp calculators.adb
gprbind main.bexch
gnatbind main.ali
gcc -c b__main.adb
gcc main.o -o main.exe

 

C# code

Microsoft Visual C# 2015
Microsoft .Net Framework version 4.6.01038

Running »Release build«

 

Java code

Java runtime:
java version “1.8.0_60”
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

 

TypeScript/JavaScript

Out of pure curiosity I wrote the same test with typescript. The results from running under node  (on the same machine) are:

Really great news is that javascript runtime under node / V8 chrome machine,  is such a great performer. With average of 7.489 sec is totally on pair with other strong typing languages.

Code is written with typescript 2.5.2, compiled to “es2017” javascript standard and run under node v8.4.0. The hardware/OS environment is the same as above.

The code in typescript:

Conclusion

I know those tests doesn’t prove anything really. But when I wrote code it is written without deep understanding of internal optimization algorithms inside runtime engines. So it is important to me which runtime will help me most without huge investment of my time.

 

 

Ada and GTK on windows

Ada and GTK+ on windows – hello world sample

Create new project with project wizard.  After initial project creation add project dependency to GtkAda.gpr from “gtk ada” installation folder: \GtkAda\lib\gnat\gtkada.gpr.

2016-08-02 22_11_26-GPS - Project - Gtk2Sample projectOr you can simply open project file (file with ‘gpr’ extension) and add “with”  statement :

“\GtkAda\bin” folder should be in the PATH.

And don’t forget to add special “windows GUI” directives to the linker, go to Project/Properties , under Build/Switches/Ada Linker add this directives in the field :

If you don’t do this, linker will create “windows console application” and additional command line window will always open with your application.

If everything was successful, compile / build will create “main.exe”  program file and if  you run from inside GPS  or from the windows file explorer, only the GTK program window should open.

2016-08-02 22_42_28-GPS - Run_ main - Gtk2Sample projectThis is probably minimal GTK project, perfect to learn Ada with graphical interface.

If you have problems with the installation, please check if everything is installed properly… You can find some hints about installation here.

Ada database – first steps

Connect to database

Using Ada for application development require access to database.

With GNATColl library is possible to work with PostgreSQL and Sqlite (embedded database).

Checking if everything is in place for database development

If you successfully install AdaCore and compile GNATColl library, you can start writing and checking if everything works as expected.

Create new project, project file must contain gnatcoll reference:

My dbsample1.gpr file contains:

And main.adb file:

You do not forget to add PostgreSQL/bin folder to local windows PATH, or copy postgres libraries to executing application folder.

If you do everything as needed, main.exe will be created and when you run it, you  will get something minimal but without any errors :