comp.lang.ada
 help / color / mirror / Atom feed
* Benchmark Ada, please
@ 2014-07-04 17:23 Victor Porton
  2014-07-05 12:34 ` Guillaume Foliard
  0 siblings, 1 reply; 11+ messages in thread
From: Victor Porton @ 2014-07-04 17:23 UTC (permalink / raw)


Somebody, write an Ada benchmark for this comparison of programming
languages:

https://github.com/jesusfv/Comparison-Programming-Languages-Economics

It seems that C++ was the fastest (faster than Fortran), but Ada may be even
faster.

If we succeed, we would advertise Ada as the fastest(!) programming language
(after assembler).

See also:
https://github.com/jesusfv/Comparison-Programming-Languages-Economics/issues/15

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-04 17:23 Benchmark Ada, please Victor Porton
@ 2014-07-05 12:34 ` Guillaume Foliard
  2014-07-05 13:00   ` Niklas Holsti
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Guillaume Foliard @ 2014-07-05 12:34 UTC (permalink / raw)


Victor Porton wrote:

> Somebody, write an Ada benchmark for this comparison of programming
> languages:
> 
> https://github.com/jesusfv/Comparison-Programming-Languages-Economics

Here is it:

---------------------------------------------------------------------
with Ada.Execution_Time;
with Ada.Numerics.Long_Elementary_Functions;
with Ada.Real_Time;
with Ada.Text_IO;

use Ada.Numerics.Long_Elementary_Functions;

use type Ada.Execution_Time.CPU_Time;

procedure Rbc_Ada
is
   
   Grid_Capital_Length      : constant := 17820;
   Grid_Productivity_Length : constant := 5;
   
   type Grid_Capital_Index is 
      new Integer range 0 .. Grid_Capital_Length - 1;
   
   type Grid_Productivity_Index is
      new Integer range 0 .. Grid_Productivity_Length - 1;
   
   type Grid_Array_Type is
      array (Grid_Capital_Index, Grid_Productivity_Index)
      of Long_Float;
   
   Null_Grid : constant Grid_Array_Type := (others => (others => 0.0));
   
   -- 1. Calibration
   
   -- Elasticity of output w.r.t. capital
   
   Alpha : constant Long_Float := 0.33333333333;
   
   -- Discount factor
   
   Beta : constant Long_Float := 0.95;
   
   -- Productivity values
   
   Productivities : constant
      array (Grid_Productivity_Index) 
      of Long_Float :=
      (0.9792, 0.9896, 1.0000, 1.0106, 1.0212);
   
   -- Transition matrix
   
   Transition : constant
      array (Grid_Productivity_Index, Grid_Productivity_Index) 
      of Long_Float :=
      ((0.9727, 0.0273, 0.0000, 0.0000, 0.0000),
       (0.0041, 0.9806, 0.0153, 0.0000, 0.0000),
       (0.0000, 0.0082, 0.9837, 0.0082, 0.0000),
       (0.0000, 0.0000, 0.0153, 0.9806, 0.0041),
       (0.0000, 0.0000, 0.0000, 0.0273, 0.9727));
   
   -- 2. Steady State
   
   Capital_Steady_State : constant Long_Float :=
      (Alpha * Beta) ** (1.0 / (1.0 - Alpha));
   
   Output_Steady_State : constant Long_Float := 
      Capital_Steady_State ** Alpha;
   
   Consumption_Steady_State : constant Long_Float := 
      Output_Steady_State - Capital_Steady_State;

   Grid_Capital_Next_Index : Grid_Capital_Index;
   
   Grid_Capital : array (Grid_Capital_Index) of Long_Float := 
      (others => 0.0);
  
   Output                  : Grid_Array_Type := Null_Grid;
   Value_Function          : Grid_Array_Type := Null_Grid;
   Value_Function_New      : Grid_Array_Type := Null_Grid;
   Policy_Function         : Grid_Array_Type := Null_Grid;
   Expected_Value_Function : Grid_Array_Type := Null_Grid;

   Max_Difference   : Long_Float := 10.0;
   Diff             : Long_Float;
   Diff_High_So_Far : Long_Float;
   
   Tolerance : constant := 0.0000001;
   
   Value_High_So_Far : Long_Float;
   Value_Provisional : Long_Float;
   Consumption       : Long_Float;
   Capital_Choice    : Long_Float;
   Iteration         : Integer := 0;
   Cpu_Time_Start    : Ada.Execution_Time.CPU_Time;
   Cpu_Time_End      : Ada.Execution_Time.CPU_Time;
begin
   Cpu_Time_Start := Ada.Execution_Time.Clock;
   
   Ada.Text_IO.Put_Line
      ("Output =" & Output_Steady_State'Img
       & ", Capital =" & Capital_Steady_State'Img
       & ", Consumption =" & Consumption_Steady_State'Img);
	
   -- We generate the grid of capital

   for Index in Grid_Capital'Range
   loop
      Grid_Capital (Index) :=
         0.5 * Capital_Steady_State + 0.00001 * Long_Float (Index);
   end loop;

   -- We pre-build output for each point in the grid
   
   for Productivity_Index in Grid_Productivity_Index
   loop
      for Capital_Index in Grid_Capital_Index
      loop
         Output (Capital_Index, Productivity_Index) := 
            Productivities (Productivity_Index)
            * Grid_Capital (Capital_Index) ** Alpha;
      end loop;
   end loop;

   -- Main iteration

   while Max_Difference > Tolerance
   loop
      for Productivity_Index in Grid_Productivity_Index   
      loop
         for Capital_Index in Grid_Capital_Index  
         loop
            Expected_Value_Function (Capital_Index, Productivity_Index) :=
               0.0;
            
            for Productivity_Next_Index in Grid_Productivity_Index   
            loop
               Expected_Value_Function (Capital_Index, Productivity_Index) 
:=
                  Expected_Value_Function (Capital_Index, 
Productivity_Index)
                  + Transition (Productivity_Index, Productivity_Next_Index)
                  * Value_Function (Capital_Index, Productivity_Next_Index);
            end loop;
         end loop;
      end loop;
      
      for Productivity_Index in Grid_Productivity_Index   
      loop
         -- We start from previous choice (monotonicity of policy function)
         
         Grid_Capital_Next_Index := 0;
         
         for Capital_Index in Grid_Capital_Index
         loop
            Value_High_So_Far := -100000.0;
            Capital_Choice    := Grid_Capital (0);
            
            for Capital_Next_Index in 
               Grid_Capital_Next_Index .. Grid_Capital_Index'Last
            loop
               Consumption := 
                  Output (Capital_Index, Productivity_Index)
                  - Grid_Capital (Capital_Next_Index);
               
               Value_Provisional :=
                  (1.0 - Beta) * Log (Consumption)
                  + Beta * Expected_Value_Function (Capital_Next_Index,
                                                    Productivity_Index);
               
               if Value_Provisional > Value_High_So_Far
               then
                  Value_High_So_Far := Value_Provisional;
                  Capital_Choice := Grid_Capital (Capital_Next_Index);
                  Grid_Capital_Next_Index := Capital_Next_Index;
                  
               else
                  exit;
               end if;
               
               Value_Function_New (Capital_Index, Productivity_Index) := 
                  Value_High_So_Far;
               
               Policy_Function (Capital_Index, Productivity_Index) :=
                  Capital_Choice;
            end loop;
         end loop;
      end loop;
      
      Diff_High_So_Far := -100000.0;
      
      for Productivity_Index in Grid_Productivity_Index   
      loop
         for Capital_Index in Grid_Capital_Index
         loop
            Diff := 
               abs (Value_Function (Capital_Index, Productivity_Index)
                   - Value_Function_New (Capital_Index, 
                                        Productivity_Index));
 
            if Diff > Diff_High_So_Far
            then
               Diff_High_So_Far := Diff;
            end if;
            
            Value_Function (Capital_Index, Productivity_Index)
               := Value_Function_New (Capital_Index, Productivity_Index);
         end loop;
      end loop;
      
      Max_Difference := Diff_High_So_Far;

      Iteration := Iteration + 1;
      
      if Iteration mod 10 = 0 or Iteration = 1
      then
         Ada.Text_IO.Put_Line ("Iteration =" & Iteration'Img
                               & ", Sup Diff =" & Max_Difference'Img);
      end if;
   end loop;
   
   Ada.Text_IO.Put_Line ("Iteration =" & Iteration'Img
                         & ", Sup Diff =" & Max_Difference'Img);
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("My check =" & Policy_Function (999, 2)'Img);
   Ada.Text_IO.New_Line;   

   Cpu_Time_End := Ada.Execution_Time.Clock;
   
   Ada.Text_IO.Put_Line
      ("Elapsed time is ="
       & Ada.Real_Time.To_Duration (Cpu_Time_End - Cpu_Time_Start)'Img);
end Rbc_Ada;
---------------------------------------------------------------------

This is mostly a line to line translation from RBC_CPP.cpp. I have
added a few type declarations though.

> It seems that C++ was the fastest (faster than Fortran), but Ada may be
> even faster.

Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:

$ gnatmake -O3 rbc_ada.adb
$ time ./rbc_ada
...
Elapsed time is = 1.966112682


As for the C++ version:

$ g++ -o testc -O3 RBC_CPP.cpp
$ time ./testc
... 
Elapsed time is   = 3.12033

So the Ada version is significantly faster. I suppose it is mainly because 
the Ada compiler has vectorized more loops than the C++ compiler (add -
ftree-vectorizer-verbose=2 to the above compilation commands to check by 
yourself).

> If we succeed, we would advertise Ada as the fastest(!) programming
> language (after assembler).

Feel free to advertise, using this Ada code as you wish.

-- 
Guillaume Foliard

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 12:34 ` Guillaume Foliard
@ 2014-07-05 13:00   ` Niklas Holsti
  2014-07-05 17:00     ` Guillaume Foliard
  2014-07-05 16:33   ` Simon Wright
  2014-07-06 17:24   ` Dirk Heinrichs
  2 siblings, 1 reply; 11+ messages in thread
From: Niklas Holsti @ 2014-07-05 13:00 UTC (permalink / raw)


On 14-07-05 14:34 , Guillaume Foliard wrote:
> Victor Porton wrote:
> 
>> Somebody, write an Ada benchmark for this comparison of programming
>> languages:
>>
>> https://github.com/jesusfv/Comparison-Programming-Languages-Economics
> 
> Here is it:

 [most of code snipped]

>    Cpu_Time_End := Ada.Execution_Time.Clock;

I have a question about this, see below.

>    Ada.Text_IO.Put_Line
>       ("Elapsed time is ="
>        & Ada.Real_Time.To_Duration (Cpu_Time_End - Cpu_Time_Start)'Img);
> end Rbc_Ada;
> ---------------------------------------------------------------------
> 
> This is mostly a line to line translation from RBC_CPP.cpp. I have
> added a few type declarations though.
> 
>> It seems that C++ was the fastest (faster than Fortran), but Ada may be
>> even faster.
> 
> Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:
> 
> $ gnatmake -O3 rbc_ada.adb
> $ time ./rbc_ada
> ...
> Elapsed time is = 1.966112682
> 
> 
> As for the C++ version:
> 
> $ g++ -o testc -O3 RBC_CPP.cpp
> $ time ./testc
> ... 
> Elapsed time is   = 3.12033

Are you sure that Ada.Execution_Time.Clock gives numbers that can be
compared with the get_cpu_time() function in the C++ version? For a
program running under an OS, it is not evident what should be included
in the "processor time" for a program (program loading, process
creation, interrupts, I/O, page faults, ...).

What did the "time" command output in your tests?

Just to be sure that the claim "Ada is faster" is really motivated.
Which would be very nice.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 12:34 ` Guillaume Foliard
  2014-07-05 13:00   ` Niklas Holsti
@ 2014-07-05 16:33   ` Simon Wright
  2014-07-05 18:25     ` Guillaume Foliard
  2014-07-06 17:24   ` Dirk Heinrichs
  2 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2014-07-05 16:33 UTC (permalink / raw)


Guillaume Foliard <guifo@wanadoo.fr> writes:

I did much the same as you. I wish I'd started from the F90 version
rather than the C++ one, it's *much* cleaner.

> Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:
>
> $ gnatmake -O3 rbc_ada.adb
> $ time ./rbc_ada
> ...
> Elapsed time is = 1.966112682
>
>
> As for the C++ version:
>
> $ g++ -o testc -O3 RBC_CPP.cpp
> $ time ./testc
> ... 
> Elapsed time is   = 3.12033
>
> So the Ada version is significantly faster. I suppose it is mainly because 
> the Ada compiler has vectorized more loops than the C++ compiler (add -
> ftree-vectorizer-verbose=2 to the above compilation commands to check by 
> yourself).

On Mac OS X (2.5 GHz Intel Core i5) I found the reverse, both with FSF
GCC 4.9.0 and GNAT GPL 2014; C++ took ~ 1s, Ada took ~ 2s.

With GCC 4.9.0, gfortran was approximately the same as C++.

Apple's C++ (Xcode 5.1.1) was approximately the same as GCC's.

-ftree-vectorizer-verbose=2 had no effect with FSF GCC.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 13:00   ` Niklas Holsti
@ 2014-07-05 17:00     ` Guillaume Foliard
  2014-07-05 18:29       ` Niklas Holsti
  0 siblings, 1 reply; 11+ messages in thread
From: Guillaume Foliard @ 2014-07-05 17:00 UTC (permalink / raw)


Hello,

Niklas Holsti wrote:
> On 14-07-05 14:34 , Guillaume Foliard wrote:
>> Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:
>> 
>> $ gnatmake -O3 rbc_ada.adb
>> $ time ./rbc_ada
>> ...
>> Elapsed time is = 1.966112682
>> 
>> 
>> As for the C++ version:
>> 
>> $ g++ -o testc -O3 RBC_CPP.cpp
>> $ time ./testc
>> ...
>> Elapsed time is   = 3.12033
> 
> Are you sure that Ada.Execution_Time.Clock gives numbers that can be
> compared with the get_cpu_time() function in the C++ version? For a
> program running under an OS, it is not evident what should be included
> in the "processor time" for a program (program loading, process
> creation, interrupts, I/O, page faults, ...).

I did these tests on Linux. On that platform, Ada.Execution_Time.Clock is 
merely a call to the POSIX call clock_gettime() (itself a system call under 
the hood), with CLOCK_THREAD_CPUTIME_ID as the clock_id parameter. In the 
GNAT GPL 2014 environment have a look at lib/gcc/x86_64-pc-linux-
gnu/4.7.4/adainclude/a-exetim.adb to notice that yourself.

Let's now check the differences between clock() and clock_gettime(). 
Consider the following C program:

#include <time.h>

int main()
{
  struct timespec ts;
  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);

  clock_t c;
  c = clock();
}

Compile it and run it with strace:

$ gcc -o test_clock test_clock.c
$ strace ./test_clock
...
clock_gettime(CLOCK_THREAD_CPUTIME_ID, {0, 760910}) = 0
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 778713}) = 0
...

We can notice that under Linux clock() is in fact a wrapper above 
clock_gettime(). So the only difference between Ada.Execution_Time.Clock and 
clock() is the clock ID given to clock_gettime(). Thus, as our programs are 
not threaded I do not expect any differences between the two.
Moreover in RBC_CPP.cpp, if you rewrite the get_cpu_time() function as 
follows:

#include <time.h>
double get_cpu_time(){
  struct timespec ts;

  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
  return (double)ts.tv_sec + (double)ts.tv_nsec / 1000000000;
}

and run the test again, you will find a value similar to the previous one.
So the timing results from my previous message are consistent.

> What did the "time" command output in your tests?

For the command it is given as argument, "time" reports the elapsed time 
("real time"), the CPU time spent in user mode ("user time") and the CPU 
time spent in system mode ("sys time"). I just used it to double check the 
CPU time values.

> Just to be sure that the claim "Ada is faster" is really motivated.
> Which would be very nice.

I suppose we are now surer than ever.

-- 
Guillaume Foliard

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 16:33   ` Simon Wright
@ 2014-07-05 18:25     ` Guillaume Foliard
  0 siblings, 0 replies; 11+ messages in thread
From: Guillaume Foliard @ 2014-07-05 18:25 UTC (permalink / raw)


Simon Wright wrote:
> Guillaume Foliard <guifo@wanadoo.fr> writes:
>> So the Ada version is significantly faster. I suppose it is mainly
>> because the Ada compiler has vectorized more loops than the C++ compiler
>> (add - ftree-vectorizer-verbose=2 to the above compilation commands to
>> check by yourself).
> 
> On Mac OS X (2.5 GHz Intel Core i5) I found the reverse, both with FSF
> GCC 4.9.0 and GNAT GPL 2014; C++ took ~ 1s, Ada took ~ 2s.
> 
> With GCC 4.9.0, gfortran was approximately the same as C++.
> 
> Apple's C++ (Xcode 5.1.1) was approximately the same as GCC's.
> 
> -ftree-vectorizer-verbose=2 had no effect with FSF GCC.

That's strange, here are my results with GCC FSF 4.9.0:

C++:
Elapsed time is   = 3.09426

Ada:
Elapsed time is = 2.111398804

C++ improved a bit, while Ada degraded, still outperforming C++.

Indeed under GCC FSF 4.9.0 the -ftree-vectorizer-verbose does not output any 
messages anymore. I have no clue why.

-- 
Guillaume Foliard


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 17:00     ` Guillaume Foliard
@ 2014-07-05 18:29       ` Niklas Holsti
  2014-07-05 18:44         ` Niklas Holsti
  2014-07-05 18:50         ` Guillaume Foliard
  0 siblings, 2 replies; 11+ messages in thread
From: Niklas Holsti @ 2014-07-05 18:29 UTC (permalink / raw)


On 14-07-05 20:00 , Guillaume Foliard wrote:
> Hello,
> 
> Niklas Holsti wrote:
>> On 14-07-05 14:34 , Guillaume Foliard wrote:
>>> Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:
>>>
>>> $ gnatmake -O3 rbc_ada.adb
>>> $ time ./rbc_ada
>>> ...
>>> Elapsed time is = 1.966112682
>>>
>>>
>>> As for the C++ version:
>>>
>>> $ g++ -o testc -O3 RBC_CPP.cpp
>>> $ time ./testc
>>> ...
>>> Elapsed time is   = 3.12033
>>
>> Are you sure that Ada.Execution_Time.Clock gives numbers that can be
>> compared with the get_cpu_time() function in the C++ version? For a
>> program running under an OS, it is not evident what should be included
>> in the "processor time" for a program (program loading, process
>> creation, interrupts, I/O, page faults, ...).
> 
> I did these tests on Linux. On that platform, Ada.Execution_Time.Clock is 
> merely a call to the POSIX call clock_gettime() (itself a system call under 
> the hood), with CLOCK_THREAD_CPUTIME_ID as the clock_id parameter.

So at least they use the same POSIX library function, good.

> In the 
> GNAT GPL 2014 environment have a look at lib/gcc/x86_64-pc-linux-
> gnu/4.7.4/adainclude/a-exetim.adb to notice that yourself.

I believe you. I was asking if you had checked that the two clock
functions are equivalent. I did not mean to criticize.

> Let's now check the differences between clock() and clock_gettime(). 
> ...
> clock_gettime(CLOCK_THREAD_CPUTIME_ID, {0, 760910}) = 0
> clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 778713}) = 0
> ...
> 
> We can notice that under Linux clock() is in fact a wrapper above 
> clock_gettime(). So the only difference between Ada.Execution_Time.Clock and 
> clock() is the clock ID given to clock_gettime().

So they are not exactly the same.

> Moreover in RBC_CPP.cpp, if you rewrite the get_cpu_time() function as 
> follows:

  [using CLOCK_THREAD_CPUTIME_ID]

> and run the test again, you will find a value similar to the previous one.

Good. (But I'm not at all sure that I would find similar values on my
host system and my compilers, as demonstrated by other posts in this
thread.)

> 
>> What did the "time" command output in your tests?
> 
> For the command it is given as argument, "time" reports the elapsed time 
> ("real time"), the CPU time spent in user mode ("user time") and the CPU 
> time spent in system mode ("sys time"). I just used it to double check the 
> CPU time values.

I know well what "time" does; I asked you to show the values it produced
so that we could see that they, too, show Ada to be faster. If you don't
want to do that, that is your right, of course.

>> Just to be sure that the claim "Ada is faster" is really motivated.
>> Which would be very nice.
> 
> I suppose we are now surer than ever.

I was not at all sure, for the reasons I gave. I am surer now, thank you.

From other posts it seems that the relative speeds of C++ and Ada for
this benchmark depend on the platform and compiler, which is not very
surprising.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 18:29       ` Niklas Holsti
@ 2014-07-05 18:44         ` Niklas Holsti
  2014-07-05 18:50         ` Guillaume Foliard
  1 sibling, 0 replies; 11+ messages in thread
From: Niklas Holsti @ 2014-07-05 18:44 UTC (permalink / raw)


To Guillaume: an apology and retraction for some text of mine which, on
rereading, is aggressive for no reason:

On 14-07-05 21:29 , Niklas Holsti wrote:
> On 14-07-05 20:00 , Guillaume Foliard wrote:
>> Niklas Holsti wrote:
>>> What did the "time" command output in your tests?
>>
>> For the command it is given as argument, "time" reports the elapsed time 
>> ("real time"), the CPU time spent in user mode ("user time") and the CPU 
>> time spent in system mode ("sys time"). I just used it to double check the 
>> CPU time values.
> 
> I know well what "time" does; I asked you to show the values it produced
> so that we could see that they, too, show Ada to be faster. If you don't
> want to do that, that is your right, of course.

I apologize to Guillaume for that aggressive reply of mine. Obviously
Guillame misunderstood my question for "time" output; I had no cause to
become annoyed by that. Sorry, Guillaume.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 18:29       ` Niklas Holsti
  2014-07-05 18:44         ` Niklas Holsti
@ 2014-07-05 18:50         ` Guillaume Foliard
  2014-07-05 19:09           ` Niklas Holsti
  1 sibling, 1 reply; 11+ messages in thread
From: Guillaume Foliard @ 2014-07-05 18:50 UTC (permalink / raw)


Niklas Holsti wrote:
>>> On 14-07-05 14:34 , Guillaume Foliard wrote:
>> In the
>> GNAT GPL 2014 environment have a look at lib/gcc/x86_64-pc-linux-
>> gnu/4.7.4/adainclude/a-exetim.adb to notice that yourself.
> 
> I believe you. I was asking if you had checked that the two clock
> functions are equivalent. I did not mean to criticize.

Oops, I was not expecting my sentence could be interpreted as if I was 
reacting to a critic. Don't worry, no harsh feelings here...

> I know well what "time" does; I asked you to show the values it produced
> so that we could see that they, too, show Ada to be faster. If you don't
> want to do that, that is your right, of course.

Sorry, I misread your question, here are the full outputs:

C++:

$ time ./testc
Output = 0.562731, Capital = 0.178198, Consumption = 0.384533
 Iteration = 1, Sup Diff = 0.0527416
Iteration = 10, Sup Diff = 0.0313469
Iteration = 20, Sup Diff = 0.0187035
Iteration = 30, Sup Diff = 0.0111655
Iteration = 40, Sup Diff = 0.00666854
Iteration = 50, Sup Diff = 0.00398429
Iteration = 60, Sup Diff = 0.00238131
Iteration = 70, Sup Diff = 0.00142366
Iteration = 80, Sup Diff = 0.00085134
Iteration = 90, Sup Diff = 0.000509205
Iteration = 100, Sup Diff = 0.000304623
Iteration = 110, Sup Diff = 0.000182265
Iteration = 120, Sup Diff = 0.00010907
Iteration = 130, Sup Diff = 6.52764e-05
Iteration = 140, Sup Diff = 3.90711e-05
Iteration = 150, Sup Diff = 2.33881e-05
Iteration = 160, Sup Diff = 1.40086e-05
Iteration = 170, Sup Diff = 8.39132e-06
Iteration = 180, Sup Diff = 5.02647e-06
Iteration = 190, Sup Diff = 3.0109e-06
Iteration = 200, Sup Diff = 1.80355e-06
Iteration = 210, Sup Diff = 1.08034e-06
Iteration = 220, Sup Diff = 6.47132e-07
Iteration = 230, Sup Diff = 3.87636e-07
Iteration = 240, Sup Diff = 2.32197e-07
Iteration = 250, Sup Diff = 1.39087e-07
Iteration = 257, Sup Diff = 9.71604e-08

My check = 0.146549

Elapsed time is   = 3.11317


real    0m3.126s
user    0m3.113s
sys     0m0.003s


Ada:

$ time ./rbc_ada
Output = 5.62731433873177E-01, Capital = 1.78198287391391E-01, Consumption = 
3.84533146481786E-01
Iteration = 1, Sup Diff = 5.27415934068824E-02
Iteration = 10, Sup Diff = 3.13469492655827E-02
Iteration = 20, Sup Diff = 1.87034598931961E-02
Iteration = 30, Sup Diff = 1.11655120338747E-02
Iteration = 40, Sup Diff = 6.66854170807507E-03
Iteration = 50, Sup Diff = 3.98429274868262E-03
Iteration = 60, Sup Diff = 2.38131180391221E-03
Iteration = 70, Sup Diff = 1.42365864508598E-03
Iteration = 80, Sup Diff = 8.51339774713189E-04
Iteration = 90, Sup Diff = 5.09205175224792E-04
Iteration = 100, Sup Diff = 3.04623244212099E-04
Iteration = 110, Sup Diff = 1.82264856321224E-04
Iteration = 120, Sup Diff = 1.09069508725246E-04
Iteration = 130, Sup Diff = 6.52764373626491E-05
Iteration = 140, Sup Diff = 3.90710821196461E-05
Iteration = 150, Sup Diff = 2.33880771197681E-05
Iteration = 160, Sup Diff = 1.40086446370757E-05
Iteration = 170, Sup Diff = 8.39131720298258E-06
Iteration = 180, Sup Diff = 5.02647453792804E-06
Iteration = 190, Sup Diff = 3.01089986365355E-06
Iteration = 200, Sup Diff = 1.80355224810302E-06
Iteration = 210, Sup Diff = 1.08034091594877E-06
Iteration = 220, Sup Diff = 6.47131694342384E-07
Iteration = 230, Sup Diff = 3.87636194032481E-07
Iteration = 240, Sup Diff = 2.32196579297295E-07
Iteration = 250, Sup Diff = 1.39087209638511E-07
Iteration = 257, Sup Diff = 9.71603565380619E-08

My check = 1.46549143695695E-01

Elapsed time is = 1.970120151

real    0m1.982s
user    0m1.970s
sys     0m0.004s

> From other posts it seems that the relative speeds of C++ and Ada for
> this benchmark depend on the platform and compiler, which is not very
> surprising.

Indeed, trying with various other compiler versions leads to somewhat 
significant differences, mostly caused by the effectiveness of the auto-
vectorization.

-- 
Guillaume Foliard

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 18:50         ` Guillaume Foliard
@ 2014-07-05 19:09           ` Niklas Holsti
  0 siblings, 0 replies; 11+ messages in thread
From: Niklas Holsti @ 2014-07-05 19:09 UTC (permalink / raw)


On 14-07-05 21:50 , Guillaume Foliard wrote:
> Niklas Holsti wrote:
>>>> On 14-07-05 14:34 , Guillaume Foliard wrote:
>>> In the
>>> GNAT GPL 2014 environment have a look at lib/gcc/x86_64-pc-linux-
>>> gnu/4.7.4/adainclude/a-exetim.adb to notice that yourself.
>>
>> I believe you. I was asking if you had checked that the two clock
>> functions are equivalent. I did not mean to criticize.
> 
> Oops, I was not expecting my sentence could be interpreted as if I was 
> reacting to a critic. Don't worry, no harsh feelings here...

Nor here.

> Sorry, I misread your question, here are the full outputs:
> 
> C++:
> 
> $ time ./testc
  ...
> Elapsed time is   = 3.11317
> 
> 
> real    0m3.126s
> user    0m3.113s
> sys     0m0.003s
> 
> 
> Ada:
> 
> $ time ./rbc_ada
   ...
> Elapsed time is = 1.970120151
> 
> real    0m1.982s
> user    0m1.970s
> sys     0m0.004s

Thanks, that is quite convincing.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Benchmark Ada, please
  2014-07-05 12:34 ` Guillaume Foliard
  2014-07-05 13:00   ` Niklas Holsti
  2014-07-05 16:33   ` Simon Wright
@ 2014-07-06 17:24   ` Dirk Heinrichs
  2 siblings, 0 replies; 11+ messages in thread
From: Dirk Heinrichs @ 2014-07-06 17:24 UTC (permalink / raw)


Guillaume Foliard wrote:

> Here are the numbers with GNAT GPL 2014 on a Core2 Q9650 @ 3.00GHz:

Tried it on my (Linux) system, Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz, FSF 
Gnat 4.6 as provided by Debian Jessie:

> $ gnatmake -O3 rbc_ada.adb
> $ time ./rbc_ada
> ...
> Elapsed time is = 1.966112682

% gnatmake -O3 Rbc_Ada.adb
% time ./Rbc_Ada
...

Elapsed time is = 1.909959513
./Rbc_Ada  1,91s user 0,00s system 97% cpu 1,972 total

> As for the C++ version:

I used g++ 4.9 on the same system:
 
> $ g++ -o testc -O3 RBC_CPP.cpp
> $ time ./testc
> ...
> Elapsed time is   = 3.12033

% g++ -o testc -O3 RBC_CPP.cpp
% time ./testc                                                                                                                           
...
 
Elapsed time is   = 2.13568
 
./testc  2,14s user 0,00s system 99% cpu 2,143 total

> So the Ada version is significantly faster

As you can see, Ada is still faster, but I wouldn't call that significantly 
;).

Bye...

	Dirk
-- 
Dirk Heinrichs <dirk.heinrichs@altum.de>
Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913
GPG Public Key CB614542 | Jabber: dirk.heinrichs@altum.de
Sichere Internetkommunikation: http://www.retroshare.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-06 17:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-04 17:23 Benchmark Ada, please Victor Porton
2014-07-05 12:34 ` Guillaume Foliard
2014-07-05 13:00   ` Niklas Holsti
2014-07-05 17:00     ` Guillaume Foliard
2014-07-05 18:29       ` Niklas Holsti
2014-07-05 18:44         ` Niklas Holsti
2014-07-05 18:50         ` Guillaume Foliard
2014-07-05 19:09           ` Niklas Holsti
2014-07-05 16:33   ` Simon Wright
2014-07-05 18:25     ` Guillaume Foliard
2014-07-06 17:24   ` Dirk Heinrichs

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