pmorissette / ffn

ffn - a financial function library for Python
pmorissette.github.io/ffn
MIT License
2.03k stars 300 forks source link

REF: Use builtin any over not np.all #31

Closed pratapvardhan closed 6 years ago

pratapvardhan commented 6 years ago

any(>limit) is faster than not np.all(<=limit) -- 2x in smaller data, 5-10x in larger data. Although, not significant in larger scheme of things. Accept this change as you seem fit :-) And, test case has been updated, to do same tests in lesser LOC.


In [138]: res = pd.Series(np.random.rand(100))

In [139]: %timeit not np.all([x <= 0.3 for x in res])
10000 loops, best of 3: 55.4 µs per loop

In [140]: %timeit any(x > 0.3 for x in res)
10000 loops, best of 3: 29.4 µs per loop

In [141]: res = pd.Series(np.random.rand(10000))

In [142]: %timeit not np.all([x <= 0.3 for x in res])
1000 loops, best of 3: 1.5 ms per loop

In [143]: %timeit any(x > 0.3 for x in res)
10000 loops, best of 3: 198 µs per loop