Python extension performance

"Martin v. Löwis" martin at v.loewis.de
Sat Apr 9 07:53:18 EDT 2005


David Jones wrote:
> Both the C++ executable and python module were linked from the same
> object files, and linked with the same options.  The only difference is
> that the Python module is linked with -shared, and the C++ code is not.
[...]
> Some potential causes of my problems:
> 
> - linking to a shared library instead building a static exe.

That is unlikely the problem - the shared library should long be loaded
when you call the function.

> - intel libraries are not being used when I think they are

Very much possible. I would do an strace on each binary (python and
your stand-alone application) to see what libraries are picked up.

> - libpython.so was built with gcc, so I am getting some link issues

Unlikely.

> - can linking to python affect my memory allocation and deallocation in
> c++??

It can - Python grabs a 128k at startup, and then another one if the
first one is exhausted. But that should not cause a performance
difference.

Other possible explanations:
- The intel compiler somehow arranges to use multiple processors in the
  code (e.g. through OpenMP); for some reason, your multiple processor
  are not used when this is run in the Python interpreter (and no,
  the GIL would not be an immediate explanation)
- The Python interpreter (unknowingly) switches the processor to a
  different floating-point operation mode, one which is less efficient
  (but, say, more correct).

Regards,
Martin



More information about the Python-list mailing list