Howdy,
I have no clue why the Calendar class is behaving thus ;)  I always use:
Date startSomething = new Date();
doSomething();
Date endSomething = new Date();
long elapsedTime = endSomething.getTime() - startSomething.getTime();

Very easy to understand.  elapsedTime will be in ms.

There are actual timing packages out there that will attempt to ensure
no other threads block the execution of the thread you're timing, etc,
in attempts to get more accurate timing information.  I haven't found
those necessary, but it's a personal choice...

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Trenton D. Adams [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, June 05, 2002 4:44 PM
>To: 'Tomcat Users List'
>Subject: Improper timing using Calendar class (JSP/servlet)
>
>I'm kind of curious.  I've been trying to do some simple performance
>timing with the Calendar class as shown below.  The startTime and
>endTime end up being the same value.  How can this be?  There should be
>at the very least a ms or two difference between them, shouldn't there?
>The same thing happens in JSP pages as it does in servlet pages.  In
>fact, in a servlet, I tried doing a Thread.Sleep (10000), and the
>startTime and endTime were still the same.  Is this a bug in tomcat?
>
>
>
><%! long startTime = Calendar.getInstance ().getTimeInMillis();%>
>
>Do some HTML output.
>
><%! long endTime = Calendar.getInstance ().getTimeInMillis();%>
>Start Time:&nbsp <%= startTime %><BR>
>End Time:&nbsp <%= endTime%><BR>
><%= endTime - startTime %><BR>
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:tomcat-user-
>[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to