Elapsed Time (Batch) Measurements
The simplest way of measuring performance is to see how long it takes to accomplish a cer-
tain task: retrieve the history of 10,000 stocks for a 25-year period and calculate the standard
deviation of those prices; produce a report of the payroll benefits for the 50,000 employees
of a corporation; execute a loop 1,000,000 times.
In the non-Java world, this testing is straightforward: the application is written, and the time
of its execution is measured. In the Java world, there is one wrinkle to this: just-in-time com-
minutes (or longer) for the code to be fully optimized and operate at peak performance. For
that (and other) reasons, performance studies of Java are quite concerned about warm-up
periods: performance is most often measured after the code in question has been executed
long enough for it to have been compiled and optimized.
OTHER FACTORS FOR A WARM APPLICATION
Warming up an application is most often discussed in terms of waiting for the compiler to optim-
ize the code in question, but there are other factors that can affect the performance of code based
on how long it has run.
JPA, for example, will typically cache data it has read from the database (see Chapter 11 ); the
second time that data is used, the operation will often be faster since the data can be obtained
from the cache rather than requiring a trip to the database. Similarly, when an application reads a
file, the operating system typically pages that file into memory. A test that subsequently reads the
same file (e.g., in a loop to measure performance) will run faster the second time, since the data
already resides in the computer's main memory and needn't actually be read from disk.
In general, there can be many places—not all of them obvious—where data is cached, and where
a warm up period matters.
On the other hand, in many cases the performance of the application from start to finish is
what matters. A report generator that processes 10,000 data elements will complete in a cer-
tain amount of time; to the end user, it doesn't matter if the first 5,000 elements are processed
50% more slowly than the last 5,000 elements. And even in something like an application
server—where the server's performance will certainly improve over time—the initial per-
formance matters. It may take 45 minutes for an application server to reach peak perform-
ance in certain configurations. To the users accessing the application during that time, the
performance during the warm-up period does matter.