What to Measure
The main measurement is always wall-clock time. You should use this measurement to specify almost all benchmarks, as it’s the real-time interval that is most appreciated by the user. (There are certain situations, however, in which system throughput might be considered more important than the wall-clock time; e.g., servers, enterprise transaction systems, and batch or background systems.)
The obvious way to measure wall-clock time is to get a timestamp
using
System.currentTimeMillis() and then subtract this from a later timestamp to
determine the elapsed time. This works well for elapsed time
measurements that are not short.[5] Other types of
measurements have to be system-specific and often
application-specific. You can measure:
CPU time (the time allocated on the CPU for a particular procedure)
The number of runnable processes waiting for the CPU (this gives you an idea of CPU contention)
Paging of processes
Memory sizes
Disk throughput
Disk scanning times
Network traffic, throughput, and latency
Transaction rates
Other system values
However, Java doesn’t provide mechanisms for measuring these values directly, and measuring them requires at least some system knowledge, and usually some application-specific knowledge (e.g., what is a transaction for your application?).
Note
You need to be careful when running tests that have small differences in timings. The first test is usually slightly slower than any other tests. Try doubling the test run so that each test is run twice ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access