Hi Istvan, It's not a surprise that the python code is slower than the equivalent C++ code. Have a look at the file src/wrapper/SWIG_files/linux_darwin/gp_wrap.cpp (the C++ file generated with swig): you can see that creating a gp_Pnt from coordinates requires that the _wrap_new_gp_Pnt function is called, then _wrap_gp_Pnt_SetCoord__SWIG_1. That means that calling gp_Pnt(0,0,0) from python runs about 50 lines of C++ code. The wrapper code size/speed is independant from the C++ function wrapped: you won't see any difference if you call OCE/OCC methods that require high computation (boolean ops, STEP import/export etc.). It's not the case when calling "atomic" methods (creating a gp_Pnt from coords for instance).
In my opinion, if you look for performance in your python code, the best way to proceed is to: - identify loops that may create a bottleneck - implement these loops in C++ functions - wrap these functions with SWIG - call the functions from python This will solve performance (as well as memory) issues. You can easily extend pythonocc with your own SWIG modules. You can for instance copy/paste the src/wrapper/Visualization folder to src/wrapper/MyFunctions. Modify the C++ and .i files, and add this new python module to the setup.py script so that it is compiled with the usual python setup.py build install. Thomas 2011/10/8 István Csanády <istvancsan...@gmail.com> > Hi, > > I made some tests with pythonOCC and with the pure C++ OCE. According > to my measurements the 'same' code in python is about 10 times slower > than the C++ code. For example the following python code: > > for i in xrange(10000): > p = gp_Pnt(0,0,0) > face = > BRepBuilderAPI_MakeFace(gp_Sphere(gp_Ax3(p,gp_Dir(1.,0.,0.)),50.)).Face() > > compared to the C++ code: > > for (int i = 0; i<10000; ++i) { > gp_Pnt p(0,0,0); > gp_Sphere sphere(gp_Ax3(p,gp_Dir(1.,0.,0.)),50.); > TopoDS_Face face = BRepBuilderAPI_MakeFace(sphere).Face(); > } > > The python version is about 8 times slower if I turn off the gc and > about 10 times if I turn it on. > > Does anybody have any perfomance tips to make the pythonOCC code faster? > > István > > _______________________________________________ > Pythonocc-users mailing list > Pythonocc-users@gna.org > https://mail.gna.org/listinfo/pythonocc-users >
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users