[C++-sig] Boost.Python is slow?
Tyomich on the AIR
cadchrk at narod.ru
Mon Jul 13 04:19:57 CEST 2009
Hello everyone! I'm currently embedding Python and have a problem. I have a struct (point) which looks like
struct TPoint
{
int x, y;
};
And I want it to be usable from Python. I made it in two ways: the first one was writing all the warpping by myself according to Python/C API, and the second was wrap it with Boost.Python. So it looks like
class_<TPoint>("TPoint")
.def_readwrite("x", &TPoint::x)
.def_readwrite("y", &TPoint::y);
It wraps ok but here is a problem: I create a huge (1000000 items) list of objects of that type:
def cr_fig(n):
res = []
while n>0:
res.append(TPoint())
n -= 1
return res
And then when I use a simple function which just increments the x member of every object, this function takes about 4 seconds to process the whole list (1000000 items) of Boost-wrapped objects and less than a second to process objects of my own wrapping! How this can be possible? Is Boost.Python much more slower than Python itself?
Regards, Artyom Chirkov.
More information about the Cplusplus-sig
mailing list