Python Forum
Understand order of magnitude performance gap between python and C++
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understand order of magnitude performance gap between python and C++
#1
**Summary: ** I observe a ~1000 performance gap between a python code and a C+ code doing the same job despite the use of parallelization, vectorization, just in time compilation and machine code conversion using Numba in the context of scientific calculation. CPU wont be used at full, and I don't understand why

Hello everybody,

I just started in a laboratory doing simulation of various material, including simulation of the growth of biological-like tissues. To do that we create a 3D version of said tissue (collection of vertices stored in a numpy array) and we apply different functions on it to mimic physic/biology.

We have a C++ code doing just that, which takes approximately 10 second to run. Someone converted said code to python, but this version takes about 2h30 hours to process. We tried every trick in the book we knew to accelerate the code. We used numba to accelerate numpy where appropriate, parallelized the code as much as we could, tried to vectorize what could be, but still the gap remains. In fact the earlier version of the code took days to proceed.

When the code execute, multiple cores are properly used, as monitored using the build-in system monitor. However, they are not used at full, and in fact deactivating cores manually does not seem to hit performances too much. At first I thought it could be due to the GIL, but releasing it had no effect on performances either. Somehow it makes me think of a bottleneck in memory transfer between the CPU and the ram, but I cannot understand why the C version would not have the same problem. I also have the feeling that there is a performance cost for calling functions. One of my earlier tasks was to refactor the code, thus decomposing complicated functions into smaller elements. I since have a small performance degradation compared to the earlier version.

I must say I am really wondering where my bottleneck is and how it could be tested/improved. Any idea would be very welcome.

I am aware my question is kind of a complicated one, so let me know if you would need additional information, I would be happy to provide.
Reply


Messages In This Thread
Understand order of magnitude performance gap between python and C++ - by ThelannOryat - Mar-15-2021, 11:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understand what it means that everything in Python is an object... bytecrunch 8 3,851 Mar-19-2021, 04:47 PM
Last Post: nilamo
  Trying to understand the python code spalisetty 2 1,896 Mar-16-2020, 08:11 AM
Last Post: javiertzr01
  I do not understand why my python looks different from tutorials. noodlespinbot 2 5,175 Oct-12-2019, 09:56 PM
Last Post: noodlespinbot
  performance kerzol81 1 1,928 Oct-07-2019, 10:19 AM
Last Post: buran
  I dont understand bytes in python. blackknite 3 4,057 Oct-02-2019, 07:39 PM
Last Post: Gribouillis
  Python performance rvkstudent 4 3,012 Apr-25-2019, 09:29 AM
Last Post: rvkstudent
  Python Turtle and order of implementation query Parsleigh 2 2,794 Mar-04-2019, 02:43 PM
Last Post: Parsleigh
  Trying to understand how import works in python patrick99e99 3 3,893 Jun-12-2018, 04:48 AM
Last Post: patrick99e99
  Python 3.6 dict key iteration order insearchofanswers87 7 5,385 May-22-2018, 05:33 PM
Last Post: snippsat
  Harmonics and their Magnitude values khanna 4 4,887 May-03-2018, 10:53 AM
Last Post: khanna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020