Get a feel for what your computer can do
When examining performance with an eye to optimization, it's worth developing a feel for how fast typical software operations actually are on modern hardware. That sense will help you know when to look deeper for the real cause of a bottleneck, or when to look elsewhere, or when to mistrust the results that your profiling tools are giving you. For instance, I ran the following short bit of code: TreeSet tree = new TreeSet (); int found = 0; long time = System.currentTimeMillis(); System.out.println("add #'s to tree"); for (int i = 0; i long time2 = System.currentTimeMillis(); System.out.println("elapsed: " + (time2 - time)); System.out.println("find #'s in tree"); for (int i = 0; i if (tree.contains(Math.random())) found++; long time3 = System.currentTimeMillis(); System.out.println("elapsed: " + (time3 - time2)); Here's the output: add #'s to tree elapsed: 8240 find #'s in tree elapsed: 5476 We see that filling a J...