Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40045 > unrolled thread

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

Started byRobin Becker <robin@reportlab.com>
First post2013-02-27 10:36 +0000
Last post2013-02-27 10:36 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: python 3 problem: how to convert an extension method into a class Method Robin Becker <robin@reportlab.com> - 2013-02-27 10:36 +0000

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

FromRobin Becker <robin@reportlab.com>
Date2013-02-27 10:36 +0000
SubjectRe: python 3 problem: how to convert an extension method into a class Method
Message-ID<mailman.2602.1361961396.2939.python-list@python.org>
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()'
> 1000000 loops, best of 3: 0.5 usec per loop
> $ python -m timeit -s 'from math import sqrt
>> class A(int):
>>      def m(self):
>>          return sqrt(self)
>> a = A(42)
>> ' 'a.m()'
> 1000000 loops, best of 3: 0.473 usec per loop
>
>
this analysis might be relevant if I wanted to use sqrt. However, in my case the 
method takes



                       py  C
utf8 bytes            50  20 usec
unicode               39  15

here py refers to a native python method and C  to the extension method after 
adding to the class. Both are called via an instance of the class.
-- 
Robin Becker

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web