On Tuesday, September 9, 2014 8:55:04 AM UTC-7, Volker Braun wrote: > > On Tuesday, September 9, 2014 4:44:33 PM UTC+1, Nils Bruin wrote: >> >> In python, looking up a global flag is going to be relatively slow, >> because, if addressed by its proper name, it involves checking several >> __dict__s >> > > Which is why it needs to be a cdef bool as I wrote earlier. >
Yes, but that's not the overhead I referred to. It's the fact that "cite" itself would live somewhere deep in the sage namespace and that the canonical way of referring to it would require several dictionary lookups. Compare: cython(""" cdef bint sage_citation_enabled = False cpdef cite(): if sage_citation_enabled: raise NotImplementedError() """) sage.misc.sageinspect.cite=cite #borrowing namespace here def t2(a): return 2*a def t4(a): sage.misc.sageinspect.cite() return 2*a sage: sage: timeit('t2(20)', number=10000000) 10000000 loops, best of 3: 302 ns per loop sage: sage: timeit('t4(20)', number=10000000) 10000000 loops, best of 3: 457 ns per loop On this trivial example it is now quite noticeable. Doing a "from sage.citation import cite" would alleviate this quite a bit as you show, but generally "from ... import ..." is discouraged in favour of leaving namespaces intact. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.