[pypy-issue] [issue1414] min()/max() performance

Kyle tracker at bugs.pypy.org
Tue Mar 5 07:50:43 CET 2013

New submission from Kyle <d.bud at me.com>:

Using pypy2.0-beta1 I have managed to get performance boost up to 20x (for 
integers) and up to 10x (for strings) of min()/max() functions when reimplemented 
them in pure python as follows:

def min_(arg):
    seq = iter(arg)
    head = seq.next()
    return reduce(min, seq, head) # min called with two args

# With exception handling for empty sequence:
def min_(arg):
    seq = iter(arg) # throws TypeError for non-iterables
        head = seq.next()
    except StopIteration:
        raise ValueError('arg is an empty sequence')
    return reduce(min, seq, head)

Could you please investigate performance on your side? I understand that min/max 
functions should also fallback to compare function for two (or small amount of) 
arguments, but given large sequences we can neglect this difference.

messages: 5411
nosy: dbud, pypy-issue
priority: performance bug
release: 2.0
status: unread
title: min()/max() performance

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list