python 3 problem: how to convert an extension method into a class Method

Robin Becker robin at
Wed Feb 27 12:28:57 CET 2013

On 27/02/2013 11:14, Peter Otten wrote:
> I think you misunderstood. You compare the time it takes to run the function
> coded in C and its Python equivalent -- that difference is indeed
> significant.

indeed. The function call overhead there looks pretty small so perhaps that's 
the way forward.

> But what I was trying to measure was the difference between two ways to wrap
> the C function:
> I expect that you will get a similar result with your actual cfunc and
> therefore can (and should IMO) use method (1) in both Python 2 and 3
> -- but of course not being able to measure it myself it may turn out I'm
> wrong.

Thanks, I suspect function calls have got faster in later pythons so my fear of 
the wrapper is outdated.

As others have pointed out I should probably be creating a method in C then I 
should be able to do something like

class A:
      def meth(self):

from extension import c_dummy_class

A.meth = c_dummy_class.c_meth
Robin Becker

More information about the Python-list mailing list