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

2013-02-27 Thread Steven D'Aprano
On Wed, 27 Feb 2013 21:49:04 +1100, Chris Angelico wrote: > On Wed, Feb 27, 2013 at 9:36 PM, Robin Becker > wrote: >> However, in my case the method takes >> >> >> >> py C >> utf8 bytes50 20 usec >> unicode 39 15 >> >> here py refers to a native

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

2013-02-27 Thread Robin Becker
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 fo

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

2013-02-27 Thread Peter Otten
Robin Becker wrote: > On 26/02/2013 18:38, Peter Otten wrote: >> Robin Becker wrote: > ...3: >> >> $ python -m timeit -s 'from new import instancemethod >>> from math import sqrt >>> class A(int): pass >>> A.m = instancemethod(sqrt, None, A) >>> a = A(42) >>> ' 'a.m()' >> 100 loops, be

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

2013-02-27 Thread Robin Becker
On 27/02/2013 10:49, Chris Angelico wrote: On Wed, Feb 27, 2013 at 9:36 PM, Robin Becker wrote: However, in my case the method takes py C utf8 bytes50 20 usec unicode 39 15 here py refers to a native python method and C to the extension m

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

2013-02-27 Thread Chris Angelico
On Wed, Feb 27, 2013 at 9:36 PM, Robin Becker wrote: > However, in my case the method takes > > > > py C > utf8 bytes50 20 usec > unicode 39 15 > > here py refers to a native python method and C to the extension method > after adding to the class

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

2013-02-27 Thread Robin Becker
On 26/02/2013 18:38, Peter Otten wrote: Robin Becker wrote: ...3: $ python -m timeit -s 'from new import instancemethod from math import sqrt class A(int): pass A.m = instancemethod(sqrt, None, A) a = A(42) ' 'a.m()' 100 loops, best of 3: 0.5 usec per loop $ python -m timeit -s '

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

2013-02-26 Thread Steven D'Aprano
On Tue, 26 Feb 2013 17:21:16 +, Robin Becker wrote: > In python 2 I was able to improve speed of reportlab using a C extension > to optimize some heavily used methods. > > so I was able to do this > > > class A: > . > def method(self,...): > > > > try: > fr

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

2013-02-26 Thread Christian Heimes
Am 26.02.2013 21:19, schrieb Ethan Furman: > Dumb question, but have you tried just assigning it? In Py3 methods are > just normal functions... > > 8<-- > class A(): > pass > > A.method = c_method > 8<-- That doesn't work with builtin functions

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

2013-02-26 Thread Peter Otten
Ethan Furman wrote: > On 02/26/2013 09:21 AM, Robin Becker wrote: >> In python 2 I was able to improve speed of reportlab using a C extension >> to optimize some heavily used methods. >> >> so I was able to do this >> >> >> class A: >> . >> def method(self,...): >> >> >>

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

2013-02-26 Thread Ethan Furman
On 02/26/2013 09:21 AM, Robin Becker wrote: In python 2 I was able to improve speed of reportlab using a C extension to optimize some heavily used methods. so I was able to do this class A: . def method(self,...): try: from extension import c_method impo

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

2013-02-26 Thread Peter Otten
Mark Lawrence wrote: > On 26/02/2013 18:38, Peter Otten wrote: >> Robin Becker wrote: >> >>> In python 2 I was able to improve speed of reportlab using a C extension >>> to optimize some heavily used methods. >>> >>> so I was able to do this >>> >>> >>> class A: >>> . >>> def metho

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

2013-02-26 Thread Mark Lawrence
On 26/02/2013 18:38, Peter Otten wrote: Robin Becker wrote: In python 2 I was able to improve speed of reportlab using a C extension to optimize some heavily used methods. so I was able to do this class A: . def method(self,...): try: from extension impo

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

2013-02-26 Thread Peter Otten
Robin Becker wrote: > In python 2 I was able to improve speed of reportlab using a C extension > to optimize some heavily used methods. > > so I was able to do this > > > class A: > . > def method(self,...): > > > > try: > from extension import c_method >

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

2013-02-26 Thread Dave Angel
On 02/26/2013 12:21 PM, Robin Becker wrote: In python 2 I was able to improve speed of reportlab using a C extension to optimize some heavily used methods. so I was able to do this class A: That creates an old-style class in Python 2.x. They've been obsolete for many years. You want to d

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

2013-02-26 Thread Robin Becker
In python 2 I was able to improve speed of reportlab using a C extension to optimize some heavily used methods. so I was able to do this class A: . def method(self,...): try: from extension import c_method import new A.method = new.instancemethod(c_method,