Java Reference
In-Depth Information
Table 12-11. Time to process single filter versus an iterator
Implemementation Time required
Multiple filters
18.0 seconds
Single filter
6.5 seconds
Iterator/count
6.8 seconds
For the sake of comparison, Table 12-11 includes (as its first line) the case where the entire
list is processed using four separate filters as opposed to the optimal case: one filter, which is
slightly faster even than an iterator.
QUICK SUMMARY
1. Filters offer a very significant performance advantage by allowing processing to
end in the middle of iterating through the data.
2. Even when the entire data set is processed, a single filter will slightly outperform
an iterator.
3. Multiple filters have some overhead; make sure to write good filters.
Summary
This look into some key areas of the Java SE JDK concludes our examination of Java per-
formance. One interesting theme of most of the topics of this chapter is that they show the
evolution of the performance of the JDK itself. As Java developed and matured as a plat-
form, its developers discovered that repeatedly generated exceptions didn't need to spend
time providing thread stacks; that using a thread-local variable to avoid synchronization of
the random number generator was a good thing; that the default size of a Concur-
rentHashMap was too large; that classloaders were not able to run in parallel due to a syn-
chronization lock; and so on.
This continual process of successive improvement is what Java performance tuning is all
about. From tuning the compiler and garbage collector, to using memory effectively, to un-
Search WWH ::




Custom Search