comp.lang.ada
 help / color / mirror / Atom feed
From: Guillaume Foliard <guifo@wanadoo.fr>
Subject: Re: Benchmark Ada, please
Date: Sat, 05 Jul 2014 19:00:57 +0200
Date: 2014-07-05T19:00:57+02:00	[thread overview]
Message-ID: <lp9b07$oph$1@speranza.aioe.org> (raw)
In-Reply-To: c1qb87F8n40U1@mid.individual.net

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

  reply	other threads:[~2014-07-05 17:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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