Performance testing in unit test
Is it necessary to conduct performance testing in unit test? If so, what is the best practice? If not, please provide the rationale.
A example could be unit test against the efficiency of a filter be asserting the time to complete filtering.
This is just an example. However, I'd like to get advice on the open question instead of a detailed solution for the question above. Thanks in advance.
No, it's certainly not necessary and probably not even useful. Not necessary because most code you write will be plenty performant, and your time is better spent elsewhere. Not useful because if you try to measure performance during your unit tests, your results will be wrong because the JVM that's running the tests almost definitely isn't similar to where your code will ultimately run in several ways including the kinds of activities occurring concurrently with the code under test, garbage collection self-tuning, general JVM settings, and JIT compilation, to name a handful.