[Numpy-discussion] How a transition to C++ could work
Sturla Molden
sturla at molden.no
Sun Feb 19 10:38:01 EST 2012
Den 19.02.2012 10:52, skrev Mark Wiebe:
>
> C++ removes some of this advantage -- now there is extra code
> generated by
> the compiler to handle constructors, destructors, operators etc
> which can
> make a material difference to fast inner loops. So you end up just
> writing
> "C-style" anyway.
>
>
> This is in fact not true, and writing in C++ style can often produce
> faster code. A classic example of this is C qsort vs C++ std::sort.
> You may be thinking of using virtual functions in a class hierarchy,
> where a tradeoff between performance and run-time polymorphism is
> being done. Emulating the functionality that virtual functions provide
> in C will give similar performance characteristics as the C++ language
> feature itself.
I agree with Mark here. C++ usually produces the faster code. C++ has
abstractions that makes it easier to write more efficient code. C++
provides more and better information to the compiler (e.g. strict
aliasing rules). C++ compilers are also getting insanely good at
optimisation, usually better than C compilers. But C++ also makes it
easy to write sluggish bloatware, so the effect on performance is not
predictable.
Sturla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120219/e3ed9576/attachment.html>
More information about the NumPy-Discussion
mailing list