0

There is a formula to calculate this based on the number of instructions, the number of cycles per instruction and the clock cycle time. Can this formula be applied to Java code? Is it possible to calculate/estimate the CPU time necessary to execute a Java method without using system time?

pjs
  • 18,696
  • 4
  • 27
  • 56
Andrei
  • 7,509
  • 7
  • 32
  • 63
  • http://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java – assylias May 15 '17 at 15:55
  • 1
    If you're asking whether runtime can be calculated simply by looking at (e.g.) JVM bytecode, the answer is no - it wouldn't take into account dynamic implementation details such as JIT compilation, CPU caching, reordering, etc. – Oliver Charlesworth May 15 '17 at 15:58
  • Is it possible to consider only the JVM bytecode, and avoid other optimisations or sources that can introduce delays/affect this timing? – Andrei May 15 '17 at 16:02
  • No, as it also depends on the CPU itself and what special instructions it offers, if any. The best you'll be able to do is calculate the time complexity of your code. – Jacob G. May 15 '17 at 17:15
  • I have the time complexity of the code, but I need to transform this to seconds (or milliseconds). I can mention all these parameters (CPU, jdk etc.), but I need to be able to calculate (or estimate) the time. Thank you. – Andrei May 15 '17 at 19:33

0 Answers0