A lot of ‘performance tests’ are posted online lately. Many
times these performance tests are implemented and executed in a
way that completely ignores the inner workings of the Java VM.
In this post you can find some basic knowledge to improve your
performance testing. Remember, I am not a professional
performance tester, so put your tips in the comments! For
example, some days ago a ‘performance test’ on while loops,
iterators and for loops was posted. This test is wrong and
inaccurate. I will use this test as an example, but there are
many other tests that suffer from the same problems. So, let’s
execute this test for the first time. It tests the relative
performance on some loop constructs on the Java VM. The first
results: Iterator – Elapsed time in milliseconds: 78 For –
Elapsed time in milliseconds: 28 While – Elapsed time in
milliseconds: 30 Allright, looks interesting. Let’s change the
test a bit. When I reshuffle the code, putting the Iterator test
at the end, I get: For – Elapsed time in millisecon