[pypy-issue] Issue #2839: max(array) is slower than expected (pypy/pypy)
ahorek
issues-reply at bitbucket.org
Tue May 29 13:18:39 EDT 2018
New issue 2839: max(array) is slower than expected
https://bitbucket.org/pypy/pypy/issues/2839/max-array-is-slower-than-expected
ahorek:
the native implementation is slower, what is the reason?
```
import datetime
import time
import random
arr_int = [random.randint(0,10000) for _ in xrange(50000)]
def maximum_native(arr):
return max(arr)
def maximum(arr):
max = arr[0]
i = 1
length = len(arr) - 1
while(i < length):
i += 1
if arr[i] > max:
max = arr[i]
return max
# warmup
for i in range(500):
maximum_native(arr_int)
for i in range(500):
maximum(arr_int)
t = time.time()
for i in range(10000):
maximum_native(arr_int)
elapsed_time = time.time() - t
print("max native: " + str(elapsed_time) + 's')
t = time.time()
for i in range(10000):
maximum(arr_int)
elapsed_time = time.time() - t
print("max: " + str(elapsed_time) + 's')
```
Python 2.7.13 (ab0b9caf307d, Apr 24 2018, 18:04:42)
[PyPy 6.0.0 with GCC 6.2.0 20160901] on linux2
**max native: 15.4919641018s**
**max: 0.683923959732s**
More information about the pypy-issue
mailing list