On Fri, May 27, 2005 at 01:49:00PM -0400, Tim Peters wrote: > Nope, it's a "cell" reference to an enclosing scope, and gets looked > up at cell-dereference speed. In my experience, that's generally a > bit slower than accessing a module global. That may have to do with a > quirk of MSVC's code generation; unsure.
Wow. If so, gcc apparently shares the same quirk. With python 2.3.5 on my ancient gentoo box, I get this (after substituting time.time for time.clock): lookup1 1.55095 lookup2 1.57738 lookup3 1.4966 This is so suprising to me that I went ahead and tried a couple of variations that I figured *must* be slower: def lookup4(arg): # Doesn't get much simpler than this. return object() class C: # ok this one is pretty silly _marker = object() def lookup5(self, arg): return self._marker lookup5 = C().lookup5 lookup1 1.53485 lookup2 1.57811 lookup3 1.47942 lookup4 2.33403 lookup5 2.0232 measurement-never-agrees-with-anyone-except-when-you-wish-it-didn't-ly y'rs, - Paul -- Paul Winkler http://www.slinkp.com _______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )