emanresu wrote:
Is there a better way to obtain timestamps in Java? I need to do some performance test in Java, and am using
Calendar.getInstance().getTimeInMillis() to grab timestamps. Unfortunately, this method seems to have some overhead. So I am just wondering if there is a better way of obtaining timestamps in Java than using Calendar. Thanks.
Not sure what you mean by overhead, but you can use System.currentTimeMillis() to do this type of thing.
Code:
public class TimeStamp {
public static void main(String[] args) {
//start timer
long time1 = System.currentTimeMillis();
//do something
//end timer
long time2 = System.currentTimeMillis();
System.out.println("time2: " + time2);
System.out.println("time1: " + time1);
System.out.println("diff: " + (time2 - time1));
System.exit(0);
}
}