> Can someone out there help me to compute the length of call using java.?

Can someone out there help me to compute the length of call using java.?

Posted at: 2014-12-18 
If you have a profiler, use that. Otherwise, measuring performance can be fun.

class OpTimer {

private int myMinCount = 10;

private long myMinSeconds = 10;

private long getMinMillis () { return 1000 * myMinSeconds; }

/** Return operation/second. */

public double timeIt () {

long startTime, now;

int count = 0;

startTime = System.currentTimeMillis ();

do {

op();

now = System.currentTimeMillis ();

} while (++count < myMinCount && now - startTime < getMinMillis());

return count / 1000.0 / (now - startTime);

}

public op () { /* subclasses should implement */

}

The unusual placement of "/ 1000.0 /" in the "return" statement is to force coercion to floating point without typing an explicit cast. It's personal preference; you can do whatever you prefer there (but you must cast to floating point before dividing the integers).

The reason we loop until we have high enough count AND have consumed at least a certain amount of time is to improve accuracy.