title: Timing with javascript performance.now()
body: <p>I am trying to time the execution of my function in milliseconds. I use <strong>performance.now()</strong> in order to do that. I am able to get the time on the first run, but on the second, third, and so on runs I get 0 milliseconds.
  Here is an example:</p>
  
  <pre><code>function someFunction (){
      var t0 = performance.now();
      //Function calculations
      var t1 = performance.now();
      Console.log(t1 - t0);
  }
  </code></pre>
  
  <p>I launch the function onclick. It works when I first launch the page. It stops working on the second click. t0 and t1 get the same values and when I subtract them I get 0 for the time. Is there anyway around it? I don't necessarily need to use performance.now(). I just want to measure time in milliseconds.</p>
  
  <p>Thank you.</p>
  
  <p><strong>Update</strong>
  I think it has everything to do with the speed.
  For example:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;html&gt;
      &lt;script type="text/javascript"&gt;
       function someFunction (){
          var t0 = performance.now();
          console.log(t0);
          //Function calculations
          //Some loop
          var counter = 0;
          for (i = 0; i &lt; 1000000; i++) { 
           counter ++;
       }
          var t1 = performance.now();
          console.log(t1);
          console.log(t1 - t0);
      }
      
      &lt;/script&gt;
      
      &lt;button type="button" onclick="someFunction()"&gt;Click me&lt;/button&gt;
      &lt;/hmtl&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Works as I would expect, but with the loop <code>for (i = 0; i &lt; 1000; i++)</code> it doesn't.</p>
  
  <p>Thank you for the pointers in the right direction.</p>