Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Function call overhead in cgo is considerable. You're right that it's not from copying, but the runtime scheduler still has to coordinate the blocking call, and the stack needs to be switched out to the C stack, kind of like a context switch.


True, just benchmarked it and found the function call overhead to be about 1.85834729e-7 seconds (185 ns). Which isn't much, but the pure C version would obviously be single nanoseconds for the handful of instructions needed depending on the function call.


185 ns is worse than function call overhead in Python (about 100 ns on this machine)


Python calling Python, Python calling out to a native module, or Python calling through ctypes?


Python calling a no-op Python function def foo(): pass


185 ns is enough to compute over 17k floating point operations on a single 3 GHz CPU (Intel Haswell/Broadwell) core.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: