Here is one other detail that I just observed.

It makes a huge difference whether the to-be-hashed object inherits
from <object> or not (timings with sage-4.6.2):

No inheritance from object:
  sage: class foo:
  ....:     @cached_method
  ....:     def __hash__(self):
  ....:         return int(1)
  ....:
  sage: f = foo()
  sage: %timeit hash(f)
  625 loops, best of 3: 1.76 µs per loop
  sage: %timeit f.__hash__()
  625 loops, best of 3: 1.87 µs per loop

The "same" class derived from object:
  sage: class bar(object):
  ....:     @cached_method
  ....:     def __hash__(self):
  ....:         return int(1)
  ....:
  sage: b = bar()
  sage: %timeit b.__hash__()
  625 loops, best of 3: 1.67 µs per loop
  sage: %timeit hash(b)
  625 loops, best of 3: 19.1 µs per loop

What is the reason that there is almost no overhead over cached_method
in the first example, but a big overhead in the second example? How
can this be improved?

Best regards,
Simon

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to