2

I've been doing some projects in computer graphics that have revolved around using open source libraries written and C/C++ that were then turned into wrappers for python.

I want to know if the performance gains for turning it into pure C/C++ would be worth the significant time it would take to rewrite the code base.

I also know C/C++ is almost always faster than python, but considering the libraries are already a C/C++ wrapper I'm not sure how much of a performance increase I should expect. I'm not looking for an exact answer since it very much depends on the circumstances, but if anyone has a general rule of thumb that'd be great!

Areisner
  • 85
  • 4

1 Answers1

5

Without seeing the code, in general it depends on

  • the granularity of the API, i.e. how much work is done by Python in relation to native code (or how often is control returning to Python),
  • whether Python code is on the critical path (some computer graphics libraries run the hot path in a separate, entirely native thread),
  • whether any compromise with regard to data structure in order to interface with Python was put in place.

Generally speaking, with a well-designed Python native library, there is little, if anything, to gain in terms of performance.

So I would start by profiling the Python code, to see if there is anything to gain.

Note also that C++ code is not fast by definition; it is only fast when it was engineered to be fast.

rustyx
  • 80,671
  • 25
  • 200
  • 267