<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class Stopwatch
{
  public $start;
  public $stop;

  public function __construct($pStarteSofort = false)
  {
    $this->start = 0;
    $this->stop = 0;
    if ($pStarteSofort) {
      $this->start();
    }
  }

  
  public function getmicrotime()
  {
    list($usec, $sec) = explode(' ', microtime());

    return ((float)$usec + (float)$sec);
  }

  
  public function start()
  {
    $this->start = $this->getmicrotime();
  }

  
  public function stop()
  {
    $this->stop = $this->getmicrotime();
  }

  
  public function elapsed()
  {
    return $this->stop - $this->start;
  }
}