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.

Need Your Help

What is the best way to write a loop with no body


I have a function func which returns true or false. Until func returns false, I want to keep calling it. What is the least awkward way to do this?

Recreating a text animation (source within)

javascript jquery animation text

I would like to recreate the text animation seen in this screen video I did of this website theme: