user3314150
user3314150

Reputation: 1

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 ?

Upvotes: 0

Views: 201

Answers (2)

dbf
dbf

Reputation: 6499

Just make a benchmark for your particular case - check how much does it take to run without time measurements.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503859

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).

Upvotes: 2

Related Questions