C-extension 2 times slower than exe

Nick Craig-Wood nick at craig-wood.com
Thu Jun 25 17:30:02 EDT 2009


Rolf Wester <rolf.wester at ilt.fraunhofer.de> wrote:
>  Hello,
> 
>  thank you all very much for your replies.
> 
>  I tried to simplify things and make the two versions as comparable as
>  possible. I put the C++ part of the program into a shared object
>  libff.so. For the exe the main function is linked against this shared
>  object. For the python stuff I made an interface consiting of only one
>  function call_solver with the same code that has the main function used
>  for the exe. Then I created a wrapper for this interface using swig and
>  linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code
>  just imports _ff and calls call_solver wich creates an object of the
>  class Solver and calls its member solve (the main function of the exe
>  does the same).
> 
>  I included some code for timing into the C++-code.
> 
>  #include <time.h>
> 
>  //beginning of solve
>  clock_t t0 = clock();
>  ...
>  clock_t t1 = clock();
>  //end of solve
>  cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl;
> 
>  I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The
>  sources are compiled using the flags -fPIC -O3.
> 
>  Timing:
> 
>  1) time python ff.py
>  time used = 3.74
>  real    0m3.234s
>  user    0m3.712s
>  sys     0m0.192s

Those times look odd because the user time is > than the real time.

User time is number of CPU seconds used.  Real time is wallclock time.

That must mean
a) your program is threading
b) there is something up with timing on your computer

Looks odd but exactly what it means I don't know!

>  2) time ff
>  time used = 2.19
>  real    0m3.170s
>  user    0m2.088s
>  sys     0m0.168s

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list