I'm making a module to simulate a neural network, speed is an issue so I've written it in c, basically you build the network in python, and then run call a simulate method that is pure c.

One thing I want to add is the ability to inject current into the network as it runs, for this I thought I would have the user define a method that takes no arguments and returns a double and the network could use this as a callback function, but then I figured this would slow down the network by calling a method written in python, then I remembered ctypes.

So I wanted to ask, is PyObject_CallObject(my_callback, NULL) any slower then calling a c function if my_callback is written in c?

9 Years
Discussion Span
Last Post by OffbeatPatriot

Of course it's slower. Whether or not it's slower enough to make any difference is the issue. For me, it's not.


Do you know what the over head is? Also, using the ctypes module, or anything really, can I get a C function pointer?


"Do you know what the over head is?"

I think I'll rephrase that. I'm fairly new to learning about the mechanisms of what makes python work so maybe this is a stupid question, but if a PyObject is basically a ctypes wrapper for a c function is the python interpreter ever used when I call PyObject_CallObject on it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.