Basically I want to be able to write a unit test that will tell me if a change I just made has changed performance. I'm aware of a similar question, but the answer to that was kind of "that's not what you want", so I'm rephrasing.
I've noticed when doing performance profiling in python that a key issue is lines of python code, and that more lines of code == worse performance. Hard to disagree with. Frequently the biggest performance gains I've got are by identifying a routine that is called unnecessarily frequently, and reducing it.
Therefore what I want is to be able to write a unit test like this:
def test_performance_of_critical_routine():
start_counting_statement_executions()
critical_routine()
stop_counting_statement_executions()
assert number_of_executions() == previously_accepted_count
The idea is that this is deterministic and the same on all platforms. If the test fails, then I can decide whether I think the regression / improvement is reasonable, and it's easy to update the test. But if there's a big change and it was unexpected, I've caught an issue at UT stage, which is always good!
I know that there are many things that affect application performance, but CPU is occasionally one of them, and I'd like to be able to catch it earlier.
Any suggestions?