|
|
||
Michael Nascimento Santos's BlogVirtual Machine ArchivesPlaying with the Tiger: Measuring nanosPosted by mister__m on February 05, 2004 at 06:41 PM | Permalink | Comments (10)Ok, sorry for not blogging for so long, but I have to work, date etc. :-D I hope this is the start of a series of small, but informative blog entries about new features available in Tiger, especially the ones a hundred people haven't mentioned before me :-D To begin with, I'll show you how to use the new nanoTime() method in Here's the code:
import static java.lang.System.*;
public class Nano {
public static void main(String[] args) {
long time = 0;
long newTime;
long smaller = 9999999999999L;
for (int i = 0; i < 100000; i++) {
time = nanoTime();
newTime = nanoTime();
smaller = Math.min(smaller, newTime - time);
}
out.println("Smallest nano interval measured: " + smaller);
out.println("Current time millis: " + currentTimeMillis());
out.println("Nano time: " + nanoTime());
}
}
Save it in javac -source 1.5 Nano.java Then run it normally with: java -cp . Nano My results (P4, 1GB RAM, Windows 2000 Pro) are: Smallest nano interval measured: 1116 Current time millis: 1076038988125 Nano time: 8736336585045 This method is intended to be used as a way to measure performance, for instance. Here, I just tried to get its precision in my current box configuration. Please let me know if you get smallest nano intervals in your platform/configuration. See you soon ;-) BREAKING NEWS: Got Tiger?Posted by mister__m on December 24, 2003 at 04:36 AM | Permalink | Comments (0)I was going to blog about Date and Calendar (and how terrible they are), but these must wait now. Straight to the point: if you want to get J2SDK 1.5.0 alpha, just go to: http://www.javalobby.org/members/j2se15.jsp This is a cooperation between JavaLobby - hey, just became a member 3 weeks ago, after years of Java, can you believe it? - and Sun. This is really a private release, so, you are not allowed to share your opinions about it with anyone except Sun. No, no feedback on this blog or any comments about J2SDK 1.5 alpha are allowed at all. You must be a member of JavaLobby to download it. Are you still reading this??? Go there and download it now! | ||
|
|