Created
April 30, 2013 13:27
-
-
Save barentsen/5488680 to your computer and use it in GitHub Desktop.
Numpy: speed of np.ptp() vs np.max()-np.min()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: import numpy as np | |
In [2]: a = np.random.random(1e2) | |
In [3]: timeit a.ptp() | |
100000 loops, best of 3: 8.3 us per loop | |
In [4]: timeit a.max()-a.min() | |
100000 loops, best of 3: 9.31 us per loop | |
In [5]: a = np.random.random(1e5) | |
In [6]: timeit a.ptp() | |
10000 loops, best of 3: 132 us per loop | |
In [7]: timeit a.max()-a.min() | |
10000 loops, best of 3: 134 us per loop | |
In [8]: a = np.random.random(1e8) | |
In [9]: timeit a.ptp() | |
10 loops, best of 3: 162 ms per loop | |
In [10]: timeit a.max()-a.min() | |
10 loops, best of 3: 161 ms per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment