java System.nanoTime is really slow. Is it possible to implement a high performance java profiler?
- by willpowerforever
I did a test and found the overhead of a function call to System.nanoTime() is at least 500 ns on my machine.
Seemed that it is very hard to have a high performance java profiler.
For enterprise software, suppose a function takes about 350 seconds and has 12,500,000,000 times of method calls. Therefore, the number of calls to System.nanoTime() is:
12,500,000,000 * 2 = 25,000,000,000 (one for start timestamp, one for end timestamp)
And the overhead of System.nanoTime in total is:
500 ns * 25,000,000,000 = 500 * 25000 s = 12500000s.
Note: all data from real case.
Any better way to acquire the timestamp?