On Thu, Apr 29, 2010 at 3:11 AM, Richard Jones <[email protected]> wrote:
> On Thu, Apr 29, 2010 at 6:26 PM, Florian Bösch <[email protected]> wrote:
>> 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.
>
> Function calls are expensive in Python.
Actually, even:
def max2(a, b): return a if a > b else b
Is faster than max(a, b). The reason is that max has two different
argument conventions and an optional keyword argument to try to
unpack.
--
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.