title: measuring the elapsed time between code segments in PHP
body: <p>From time time to time, I'd like to be able to measure the elapsed time between two segments of code. This is solely to be able to detect the bottlenecks within the code and improve what can be improved. </p>
  
  <p>I'd like to design a function like that where the function should work with a global variable which  echoes out the elapsed time between the current call and the last time it was called.  </p>
  
  <p>This way, you can use it many times one after the other. </p>
  
  <p>And the function should be able to be calculate the differences in fractions of seconds such as 0.1 sec or 0.3 sec etc.</p>
  
  <p>An example would probably explain it much better. </p>
  
  <pre><code>echo time_elapsed();   
  
       // This echo outputs nothing cause this is the starting case. 
       // There is nothing to compare against. 
  
  //
  // 1st code section here
  //
  
  echo time_elapsed();  
  
        // This echo outputs 0.5 seconds. 
        // ...which means there has been 0.5 seconds passed 
        // ...since the last time time_elapsed() was fired
  
  //
  // 2nd code section here
  //
  
  
  echo time_elapsed()   
  
        // This echo outputs 0.2 seconds
  
  //
  // 3rd code section here 
  //
  
  echo time_elapsed()   
  
        // This echo outputs 0.1 seconds etc
  </code></pre>
  
  <p>My question is what PHP utilities ( built-in functions ) do I need to use to achieve this kind of output?</p>