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

Kyle tracker at bugs.pypy.org
Tue Mar 5 09:22:23 CET 2013


Kyle <d.bud at me.com> added the comment:

Hi again,

I have tried nightly (pypy-c-jit-61992-6fe2c02099ef-win32) and still got boost:

code:
import time

class measure:
	def __init__(self, description, size, runs):
		self.description = description
		self.size = size
		self.runs = runs

	def __enter__(self):
		self.start = time.time()

	def __exit__(self, *args):
		elapsed = time.time() - self.start
		print '%.2lf runs/sec, %s, size = %d, %d runs' % (self.runs / elapsed, 
self.description, self.size, self.runs)

def min_(arg):
	seq = iter(arg)
	try:
		head = seq.next()
	except StopIteration:
		raise ValueError('arg is an empty sequence')
	return reduce(min, seq, head)

N = 1000
N_max = 100000000
while N <= N_max:
	K = 5 * N_max / N
	
	r = range(N)

	with measure('built-in', N, K):
		for _ in range(K):
			min(r)

	with measure('with reduce', N, K):
		for _ in range(K):
			min_(r)

	print
	N *= 10

output:

372300.84 runs/sec, built-in, size = 1000, 500000 runs
692520.66 runs/sec, with reduce, size = 1000, 500000 runs

29994.00 runs/sec, built-in, size = 10000, 50000 runs
77279.74 runs/sec, with reduce, size = 10000, 50000 runs

4012.84 runs/sec, built-in, size = 100000, 5000 runs
7874.02 runs/sec, with reduce, size = 100000, 5000 runs

388.50 runs/sec, built-in, size = 1000000, 500 runs
791.14 runs/sec, with reduce, size = 1000000, 500 runs

30.79 runs/sec, built-in, size = 10000000, 50 runs
79.24 runs/sec, with reduce, size = 10000000, 50 runs

0.98 runs/sec, built-in, size = 100000000, 5 runs
7.90 runs/sec, with reduce, size = 100000000, 5 runs

----------
status: resolved -> chatting

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1414>
________________________________________


More information about the pypy-issue mailing list