Thanks Micheal, I do get better resolution timing now J
 
I am also trying to time how long it takes a particular message to travel from 
identical machines A to B. That is propagation time = receive time – sent time. 
I cannot use System.nanoTime(); in this case and the resolution of 
System.currentTimeMillis() (i.e. 15.625ms) is unacceptable:
 
On Machine A:
long sent_time = System.currentTimeMillis();
out.write (msg);
 
On Machine B:
in.read(msg);
long receive_time = System.currentTimeMillis();
 
Despite synchronizing the time on the two machines using NTP, I am getting not 
only poor resolution but also negative propagation values which are ridiculous. 
Any idea about how I can get better resolution is this scenario?
 
Regards,
Sana

--- On Tue, 6/24/08, Michael Erskine <[EMAIL PROTECTED]> wrote:

From: Michael Erskine <[EMAIL PROTECTED]>
Subject: RE: precision of log4j
To: "Log4J Users List" <log4j-user@logging.apache.org>
Date: Tuesday, June 24, 2008, 4:16 PM

> From: sana qadir [mailto:[EMAIL PROTECTED]
> Sent: 24 June 2008 05:40
> Subject: precision of log4j
> I am using log4j to help me record the execution times of several
> functions (1 to n) using code similar to the following snippet:
>
> logger.debug("Timestamp before...");
> function_n();
> logger.debug("Timestamp after...");

OK, Log4J isn't necessarily going to do what you want: if you want high
resolution timings you can use System.nanoTime and to make the timings
accurate, don't corrupt them by logging while you're timing...

long t1 = System.nanoTime();
function_n();
long t2 = System.nanoTime();

logger.debug("duration in nanos: "+(t2 -t1));


Regards,
Michael Erskine.


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


      

Reply via email to