A small profiler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Profiler { | |
public $time = 0; | |
public $memory = 0; | |
public function startRecordTime(){ | |
$this->time = microtime(true); | |
} | |
public function stopRecordTime(){ | |
$recordedTime = microtime(true) - $this->time; | |
$this->time = 0; | |
return $recordedTime; | |
} | |
public function startRecordMemory(){ | |
$this->memory = memory_get_usage(); | |
} | |
public function stopRecordMemory(){ | |
$recordedMemory = memory_get_usage() - $this->memory; | |
$this->memory = 0; | |
return $recordedMemory; | |
} | |
} | |
$profiler = new Profiler(); | |
/** | |
* Object hashing tests. | |
*/ | |
$sos = new SplObjectStorage(); | |
$docs = array(); | |
$iterations = 100000; | |
for ($i = 0; $i < $iterations; ++$i) { | |
$doc = new DOMDocument(); | |
//$doc = new stdClass(); | |
$docs[] = $doc; | |
} | |
$profiler->startRecordMemory(); | |
$profiler->startRecordTime(); | |
// Load the SplObjectStorage | |
foreach ($docs as $d) { | |
$sos->attach($d); | |
} | |
echo 'Time: ' . $profiler->stopRecordTime(); | |
echo '<br>'; | |
echo 'Memoryusage: ' . $profiler->stopRecordMemory(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment