Skip to content

Instantly share code, notes, and snippets.

@mbunge
Created March 26, 2013 14:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbunge/5245961 to your computer and use it in GitHub Desktop.
A small profiler.
<?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