This optimizes the code in find_extrema from O(2^N) to O(N) (i.e. exponential to linear increase in runtime with increasing signal size). A signal with 1mil samples took 4.7s to run vs 0.9s after these changes. Before, a signal with 10's of millions of samples would take several minutes to run trough find_extrema before I became impatient and killed the process.
This optimizes the code in
find_extrema
from O(2^N) to O(N) (i.e. exponential to linear increase in runtime with increasing signal size). A signal with 1mil samples took 4.7s to run vs 0.9s after these changes. Before, a signal with 10's of millions of samples would take several minutes to run troughfind_extrema
before I became impatient and killed the process.