I\'m working on a project which is in serious need of some performance tuning.
How do I write a test that fails if my optimizations do not in improve the speed of the pr
Run the tests + profiling in CI server. You can also run load tests periodically.
You are concerned about differences (as you mentioned), so its not about defining an absolute value. Have an extra step that compares the performance measures of this run with the one of the last build, and report on the differences as %. You can raise a red flag for important variations of time.
If you are concerned on performance, you should have clear goals you want to meet and assert them. You should measure those with tests on the full system. Even if your application logic is fast, you might have issues with the view causing you to miss the goal. You can also combine it with the differences approach, but for these you would have less tolerance to time variations.
Note that you can run the same process in your dev computer, just using only the previous runs in that computer and not a shared one between developers.