C-extension 2 times slower than exe

MRAB python at mrabarnett.plus.com
Fri Jun 26 00:49:37 CEST 2009


Nick Craig-Wood wrote:
> 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
> 
Perhaps multithreading on dual cores?



More information about the Python-list mailing list