Frst, if you care about performance in Python (which is not always reasonable, but you need to talk about this differently), you should use the timeit module . Even in C, it's hard to predict how some functions will behave after compilation, and it's harder in Python. People often confidently express which features are faster, depending on the data. Then - using timeit, I mean - you could recognize yourself.
Secondly, if you really care about performance in float lists, you should not use lists at all, but numpy arrays. Using IPython here, under Python 2.7.2, which makes synchronization easier:
In [41]: import random, numpy In [42]: a = [0.1*i for i in range(10**5)] In [43]: timeit min(a) 100 loops, best of 3: 4.55 ms per loop In [44]: timeit sorted(a)[0] 100 loops, best of 3: 4.57 ms per loop In [45]: random.shuffle(a) In [46]: timeit min(a) 100 loops, best of 3: 6.06 ms per loop In [47]: timeit min(a)
And we will note a few things. (1) Python sorting (timsort) works very well on data that sorted runs, so sorting an already sorted list has virtually no penalty. (2) Sorting a random list, on the other hand, is much slower, and this will only get worse as the data grows. (3) Numpy.min () in a float array is sixty times faster than min in a Python list, because it does not have to be shared.
source share