On Apr 29, 8:50 am, Joe Wreschnig <[email protected]> wrote: > A quick timeit bears out the 3x claim: > $ python -m timeit "a = 1; b = 2; c = max(a, b)" > 1000000 loops, best of 3: 0.438 usec per loop > $ python -m timeit "a = 1; b = 2; c = a if a > b else b" > 10000000 loops, best of 3: 0.153 usec per loop Geeze, that's crazy.
> I like this, but I'm not sure how it could be implemented efficiently. > If you use try/except, setting the scale becomes much more expensive > than it is now. If you use isinstance, it's not as bad, but you have > to hope no one passes in a strange sequence type. You mean in order to be backwards compatible to doing somesprite.scale = 1.0? Well, there's two solutions: 1) Break backwards compatibility and assume a two component sequence, i.e. def _set_scale(self, (x, y)) and you do not need to worry about "strange sequence types" 2) make a check for the backwards compatibility case, i.e. if isinstance(scale, numbers.Real): x, y = scale, scale; else: x, y = scale; and you also do not need to worry about strange sequence types, because either unpacking works, or it doesn't, in which case the traceback leads to the somesprite.scale = something line -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
