A story about this — 5 years ago
Code Complete<img src=“http://www.assoc-amazon.com/e/ir?t=buddhistbookr-20&l=ur2&o=1” width=“1” height=“1” border=“0” alt="" style=“border:none !important; margin:0px !important;” / >, on the subject of measuring performance, from Chapter 25, page 604:
Whether you use someone else’s tool or write your own code to make the measurements, make sure that you’re measuring only the execution time of the code you’re tuning. Use the number of CPU clock ticks allocated to your program rather than the time of day. Otherwise, when the system switches from your program to another program, one of your routines will be penalized for the time spent executing another program.Nice point, since in many Java examples I’ve seen System.currentTimeMillis() used to time sections of code, as is done in this article on micro-tuning. I’ve done it myself. It’s probably pretty safe for some uses, but something that you should think twice about in others.