Hi Nicolas, Florent and Maarten,

On 13 Sep., 10:07, Simon King <simon.k...@uni-jena.de> wrote:
> The new metaclass provides a fast hash, and thus can be useful in
> applications that frequently work with, say, dictionary keys. However,
> there is no free lunch. The fast hash currently comes with a
> regression in accessing the other attributes:

It turns out that I could reduce the price of the lunch!

Now, there is a *general* speedup for attribute access:
{{{
sage: from sage.misc.fast_hash import FastHashMetaclass
sage: F = CombinatorialFreeModule(QQ, ['a','b'])
sage: D = dir(F)
sage: timeit('for s in D: a = getattr(F,s)', number=10000)
10000 loops, best of 3: 84.1 µs per loop
sage: timeit("hash(F)")
625 loops, best of 3: 1.09 µs per loop
sage: F.__class__ = FastHashMetaclass(F.__class__)
sage: timeit('for s in D: a = getattr(F,s)', number=10000)
10000 loops, best of 3: 64.4 µs per loop
sage: timeit("hash(F)")
625 loops, best of 3: 443 ns per loop
sage: TestSuite(F).run()
}}}

The price to pay is that the class' dictionary is enlargend.
{{{
sage: len(F.__class__.__dict__.keys())
205
sage: len(F.__class__.__base__.__dict__.keys())
4
}}}

Perhaps Python experts know a good reason to not blow up the class
dictionary; so, I'd appreciate comments on #11794.

Cheers,
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