System.currentTimeMills Execution time

we are using one web service which works usually in 30-40 ms time.Inside that web service we are calling System.currentTimeMills for 38 times for calculating the time taken in various methods inside that service.

i just wanted to know if it is feasible to call this method more then 38 times from a code which is taking less then 40 ms ?? what is the overhead associated with this method ?

Jon Skeet
people
quotationmark

Yes, it's absolutely feasible to call it hundreds of thousands of times in that period. It doesn't have a huge amount of overhead - but it's not what you should be calling for time measurement anyway. Use System.nanoTime() instead, which is specifically designed for accurately measuring elapsed execution time, rather than telling the current wall time.

As a rough measure of the overhead, on my laptop, after JIT warmup, it takes about 14 milliseconds to call System.nanoTime() a million times. So calling it 38 times in the course of 40 milliseconds won't be much of an issue (assuming your system has about the same overhead; it may well depend greatly on hardware and OS).

people

See more on this question at Stackoverflow