You are correct about the formatting. It was just convient to do:
....
timer.start();
.... long code....
timer.stop();
log.info( "Operation took " + timer.getSecondsWithMilliseconds() ); // Formatted string


Although I can get the 'raw' time in milliseconds as well if needed by some other component.

- Robert

Shapira, Yoav wrote:

Howdy,
So then you're all set.  I would point out that logging and formatting
are not strictly necessary for timing operations and may be better
handled by the logging component, e.g. log4j, rather than the timing
component.  But that's a very individual decision to the app and the
designer.

Yoav Shapira
Millennium ChemInformatics




-----Original Message-----
From: Robert McIntosh [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 11, 2003 12:12 PM
To: Jakarta Commons Developers List
Subject: Re: [OT] timers

I started out using that approach, and then wrote a simple class that
does that via a start() and stop() method, then formats the results for
logging and other purposes. So the output looks like "1s: 345ms". There
are a couple of other formats for just milliseconds, just seconds, etc.
Makes it easy to read :-)

- Robert

Shapira, Yoav wrote:



Howdy,
I tend to use the simplest of all:

long opStart = System.currentTimeMillis();
... do stuff ...
long opEnd = System.currentTimeMillis();
... elapsed time in milliseconds = opEnd - opStart

I know this approach isn't 100% accurate due to threading issues, CPU
cycles, etc, but it's good enough for every application I've ever
written/used.  It's also consistent, simple to use, and incurs no
overhead.

You will undoubtedly find many timing utilities if you try a google
search.  I haven't found one that claims to always be 100% accurate in
the face of threading issues, so why bother using anything but the
simplest? ;)

Yoav Shapira
Millennium ChemInformatics






-----Original Message-----
From: Robert McIntosh [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 11, 2003 11:54 AM
To: Commons
Subject: [OT] timers

Does anyone know of a good timer utility, maybe there is one hidden


in


commons somewhere? I don't mean a timer like the java.util.Timer and




the




javax.swing.Timers which are schedule types, but a timer for well,
timing operations. I have a simple one I wrote that works, but I


didn't


know if there were any others that might be better.

- Robert


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






This e-mail, including any attachments, is a confidential business


communication, and may contain information that is confidential,
proprietary and/or privileged. This e-mail is intended only for the
individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else. If you are not the(an)


intended


recipient, please immediately delete this e-mail from your computer


system


and notify the sender. Thank you.


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





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






This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.


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





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



Reply via email to