ctypes and speed

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 49
Reputation: OffbeatPatriot is an unknown quantity at this point 
Solved Threads: 0
OffbeatPatriot OffbeatPatriot is offline Offline
Light Poster

ctypes and speed

 
0
  #1
Jun 26th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: ctypes and speed

 
0
  #2
Jun 26th, 2009
Of course it's slower. Whether or not it's slower enough to make any difference is the issue. For me, it's not.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 49
Reputation: OffbeatPatriot is an unknown quantity at this point 
Solved Threads: 0
OffbeatPatriot OffbeatPatriot is offline Offline
Light Poster

Re: ctypes and speed

 
0
  #3
Jun 27th, 2009
Do you know what the over head is? Also, using the ctypes module, or anything really, can I get a C function pointer?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 49
Reputation: OffbeatPatriot is an unknown quantity at this point 
Solved Threads: 0
OffbeatPatriot OffbeatPatriot is offline Offline
Light Poster

Re: ctypes and speed

 
0
  #4
Jun 29th, 2009
"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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC