Gaurav wrote:
http://www.sys-con.com/story/print.cfm?storyid=45250
Any comments?
Those tests expose one regularity - the examples where OS support is
extensively used are slower than those where the entire code in
performed in process space. Performance of the former suffers from
user/kernel mode switching and if it is done at least once per loop
iteration the impact must be pretty visible.
So all C++ examples with extensive heap or stack (function calls) memory
allocation must be slower than corresponding Java examples where similar
functionality is performed by the JVM directly in the user process space
(Fibonacci, hash, object creation).
Of course if one is ready to pay with slower startup and bigger memory
consumption then he/she may can have the same in C++ using inlining,
memory pool and other commonly used techniques.
When such handicaps are not introduced (nested loop, random numbers) C++
performs faster as expected.
One thing surprised me. For the reason described above I expected the
method call example to be slower in any case in C++ than in Java, then
after looking at the code it appeared that all member functions were
coded inline and at least some of them were optimized away by the
compiler. So this test does not fulfil its goal. The other ones also
introduce some unnecessary temporary variables etc. and should not be
used as representative C++ code.
Regards,
Janusz