cvanelteren / PlexSim

Computational toolbox for complex (adaptive) system simulations
6 stars 1 forks source link

C++ Slower than Cython #2

Closed cvanelteren closed 3 years ago

cvanelteren commented 4 years ago

Using pybind11 c++ runs slower when called from python. Possible reasons

The overhead is slight. Here are some timings.

Model::samplingNodes

Testing size 10, 10
cython
Time taken  0.0009996891021728516
cpp
Time taken  0.012464523315429688
Testing size 50, 50

cython
Time taken  0.012415647506713867
cpp
Time taken  0.30524206161499023
Testing size 100, 100

cython
Time taken  0.05557751655578613
cpp
Time taken  1.2959299087524414

Potts::simulate

Testing size 10, 10

cython
Time taken  0.15047907829284668
cpp
Time taken  0.13630414009094238
Testing size 50, 50

cython
Time taken  3.0491204261779785
cpp
Time taken  3.568964719772339
Testing size 100, 100

cython
Time taken  13.722956895828247
cpp
Time taken  16.905017137527466
cvanelteren commented 4 years ago

Wrote some rust code; seems to be even slower for some reason that the cpp code. RNG is faster at lower scale (maybe declaration of ndarray?). Will have a closer look due to semantics being a bit better.

cvanelteren commented 3 years ago

Using CRTP the gap "nearly" disappeared. Cython seems to be (if written correctly) highly optimized both in terms of compiler flags and its implementation.