This demonstrate how c++ is faster then C.
On my PC C++ run 18 times more fast then C.
Look at:
http://www.research.att.com/~bs/new_learning.pdf
Try yourself the respective C and C++ code sample at pages 4 and 5.
Create a big file with a list of number to elaborate and sort and add
a logging for the time (one at the start and one at the end of main in
both files).
compile these two source files and see yourself at logs.
C++ is faster!!!
Well, it sometimes has more efficient libraries (and as BS points out,
some of them are intrinsically more efficient because they know the
types of the items they are handling, like sort versus qsort). On the
other hand, some of the C++ libraries are less efficient in other ways
(particularly memory usage, some implementations of strings are horribly
wasteful of both memory and time because they copy rather than using
reference counting).
Compiling, however, is much slower for C++ than for C (on my machine,
using the same compiler on the same code the ratio is typically 2:1;
with equivalent but idiomatic C++ code (for instance those two BS
examples) it is more) and uses a lot more memory. And the executable
files for idiomatic C++ code are always bigger (for C code compiled as
C++ -- where that is valid -- they are about the same).
And of course one can depend on a C compiler being available on any real
operating system on a production machine, whereas C++ compilers are
still only on a minority of them (and those are ones used for
development)...
Chris C