12

C might be a pain to write, but holy cow does it run circles around python from a performance perspective. Easy to forget in fields like data science, where python is the default

Comments
  • 3
    @dudeking
    Even for a scripting-language, Python is slow.
  • 6
    Are we talking pure Python or Python with libraries? Because if you're doing numerical stuff and you use the right library the right way, Python can be extremely fast because it's just acting as a convenience wrapper for heavily optimized lower level code (which is why it's so valuable). A good Python data science library will probably outperform a homegrown C program (especially as you scale up) unless you really know what and how to tune exactly right.
  • 0
    Of course its easy to forget when R runs circles around both of them in its own way; more user-friendly and manageable than C, lightning fast compared to numpy and pandas.
  • 1
    @arcsector a shame R is dying, losing against python even in data domain.
  • 1
    We recently did a test with python vs c++ in data science.
    We implemented the same procedure (recognising circles in an image, preprocessing the roi, detecting whether or not the part in the roi is broken, etc) and funny enough, python was a few ms faster.

    Propably because we used Opencv on both to keep the arguments the same.
    I could share the 7 pages paper but it's a) in German and b) not really written in the scientific way I would like.
  • 1
    @Emphiliis is not python data related libraries written in cpp/c?
  • 1
    Yes they are. Opencv basically uses a mapping to their cpp library. But would you not expect pure cpp to be faster either way?
  • 0
    @Emphiliis not really, if you're not careful in C++ you can introduce tons of inefficiencies into your program just in object management and all that, while python will be more automated and generically fast by default.

    Where c++ beats python is the speed of its basic operations (direct machine code after all) and its ability to be optimized, using a profiler you can optimize the living crap out of your program, but that takes a lot of time and may not even be worth it in many situations. Python isn't so susceptible to optimization, you're sort of stuck with what you're given.
Add Comment