<?php
/**
* ベンチマーククラス
*
* PHP version 5
*
* @package    core
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/

class Benchmark{

	private $_start;
	private $_stop;
	private $_score;


	/*
	 *    コンストラクタ
	 */
	public function __construct( $auto_start = TRUE )
	{
		$this->_start = 0;
		$this->_stop = 0;
		$this->_score = 0;

		if ( $auto_start ){
			$this->start();
		}
	}

	/*
	 *    スコア
	 */
	public function getScore()
	{
		return $this->_score;
	}

	/*
	 *    開始
	 */
	public function start(){
		$this->_start = $this->_now();
	}

	/*
	 *    終了
	 */
	public function stop(){
		$this->_stop = $this->_now();
  		$this->_score = round( $this->_stop - $this->_start, 5 );
		return $this->_score;
	}

	/*
	 *    現在時間を取得
	 */
	private function _now(){ 
		list($msec,$sec) = explode(' ',microtime()); 
		return ( (float)$msec + (float)$sec );
	}

}


?>
