note 90216 modified in function.microtime by danbrown

From: Date: Fri, 10 Apr 2009 18:37:35 +0000
Subject: note 90216 modified in function.microtime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153055@lists.php.net to get a copy of this message
<?php class StopWatch { public $total; public $time; public function __construct() { $this->total = $this->time = microtime(true); } public function clock() { return -$this->time + ($this->time = microtime(true)); } public function elapsed() { return microtime(true) - $this->total; } public function reset() { $this->total=$this->time=microtime(true); } } $stopwatch = new StopWatch(); usleep(1000000); echo "Checkpoint 1: ".$stopwatch->clock()." seconds<br />"; usleep(1000000); echo "Checkpoint 2: ".$stopwatch->clock()." seconds<br />"; echo "Total Elapsed: ".$stopwatch->elapsed()." seconds<br />"; ?> --was-- class StopWatch { public $total; public $time; public function __construct() { $this->total = $this->time = microtime(true); } public function clock() { return -$this->time + ($this->time = microtime(true)); } public function elapsed() { return microtime(true) - $this->total; } public function reset() { $this->total=$this->time=microtime(true); } } $stopwatch = new StopWatch(); usleep(1000000); echo "Checkpoint 1: ".$stopwatch->clock()." seconds<br />"; usleep(1000000); echo "Checkpoint 2: ".$stopwatch->clock()." seconds<br />"; echo "Total Elapsed: ".$stopwatch->elapsed()." seconds<br />"; http://php.net/manual/en/function.microtime.php

« previous php.notes (#153055) next »