C
cppaddict
I found the code below in an interesting article about how to measure
execution time with greater accuracy than System.currentTimeMillis()
offers:
http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html
My question is about the first "for" loop in the code below, which,
according to the comments, is intended to "warm up" hotspot. Can
someone explain what it's doing there? Why do you need to warm up
hotspot? Does it create performance gains? If so, how and why?
Thanks,
John
public static void main (String [] args)
{
// JIT/hotspot warmup:
for (int r = 0; r < 3000; ++ r) System.currentTimeMillis ();
long time = System.currentTimeMillis (), time_prev = time;
for (int i = 0; i < 5; ++ i)
{
// Busy wait until system time changes:
while (time == time_prev)
time = System.currentTimeMillis ();
System.out.println ("delta = " + (time - time_prev) + "
ms");
time_prev = time;
}
}
execution time with greater accuracy than System.currentTimeMillis()
offers:
http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html
My question is about the first "for" loop in the code below, which,
according to the comments, is intended to "warm up" hotspot. Can
someone explain what it's doing there? Why do you need to warm up
hotspot? Does it create performance gains? If so, how and why?
Thanks,
John
public static void main (String [] args)
{
// JIT/hotspot warmup:
for (int r = 0; r < 3000; ++ r) System.currentTimeMillis ();
long time = System.currentTimeMillis (), time_prev = time;
for (int i = 0; i < 5; ++ i)
{
// Busy wait until system time changes:
while (time == time_prev)
time = System.currentTimeMillis ();
System.out.println ("delta = " + (time - time_prev) + "
ms");
time_prev = time;
}
}