title: CPU execution time in Java
body: <p>I want to calculate how much CPU time my function takes to execute in Java. Currently I am doing as below.</p>
  
  <pre><code>   long startTime = System.currentTimeMillis();
      myfunction();
      long endTime = System.currentTimeMillis();
      long searchTime = endTime - startTime;
  </code></pre>
  
  <p>But I found out that for the same I/P I get different time depending on system load.</p>
  
  <p>So, how to get exact CPU time my function took to execute. </p>