title: How to get the execution time in small fraction using currentTimeMillis() method
body: <p>I need to get the execution time for a function in Java. I am aware of two methods I can use:
  <code>currentTimeMillis();</code> and <code>nanoTime();</code> But I have learned that <code>currentTimeMillis();</code> is more accurate if I need the wall-clock time (i.e, as if I am measuring from the wall-clock how much time the execution took. Not the processing time). </p>
  
  <p>But <code>currentTimeMillis();</code> can not give me small fraction number. For example, if the execution time is less than 1 millisecond, it returns 0. I need the time even if it is less than 1, say, 0.05 ms. This is a simple example when the method returns 0.</p>
  
  <pre><code>long startTime=System.currentTimeMillis();
  for(int x=0; x&lt;10;x++)
  {
      System.out.println("-");
  }
  
  long execTime=System.currentTimeMillis() - startTime;
  </code></pre>
  
  <p>Even if it returns time, it return it as 30 or 40. But, I need a more precise number, say, 30.00012. Also, the method return type is <code>long</code> but I changed it to <code>double</code> as I want the number in a floating point, is there any harm in this? Can you tell me to the proper way by which I can measure my java method execution wall-clock time in small fraction number (e.g. not 8.0 but 8.287335)</p>