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 autolearn=unavailable autolearn_force=no version=3.4.4 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!aioe.org!.POSTED!not-for-mail From: Guillaume Foliard Newsgroups: comp.lang.ada Subject: Re: Benchmark Ada, please Date: Sat, 05 Jul 2014 19:00:57 +0200 Organization: /\/\/\/ Message-ID: References: NNTP-Posting-Host: 5N227f1IERa0rAVWs/hFMg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.5 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:20727 Date: 2014-07-05T19:00:57+02:00 List-Id: 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 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 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