1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class timer
9{
10	function parseMicro($micro)
11	{
12		list($micro, $sec) = explode(' ', microtime());
13
14		return $sec + $micro;
15	}
16
17	function start($timer = 'default', $restart = false)
18	{
19		//if (isset($this->timer[$timer]) && !$restart) {
20			// report error - timer already exists
21		//}
22		$this->timer[$timer] = $this->parseMicro(microtime());
23	}
24
25	function stop($timer = 'default')
26	{
27		$result = $this->elapsed($timer);
28		unset($this->timer[$timer]);
29		return $result;
30	}
31
32	function elapsed($timer = 'default')
33	{
34		return $this->parseMicro(microtime()) - $this->timer[$timer];
35	}
36}
37