Draft Forbes Group Website (Build by Nikola). The official site is hosted at:
License: GPL3
ubuntu2004
Python Performance
Here we compare various approaches to solving some tasks in python with an eye for performance. Don't forget Donald Knuth's words:
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.
In other words, profile and optimize after making sure your code is correct, and focus on the places where your profiling tells you you are wasting time.
Numpy
where vs piecewise
Summary: piecewise
only wins when you have really large arrays. It does vectorize over the portions of the array, though, so is a good choice if you have very expensive functions. For this example, is about the tipping point. Beware of the gotcha though.