<?php
include_once 'CTimer.php';
date_default_timezone_set('UTC');
$timer = new CTimer(true); //page timer
//processor wait
$db = new CQuasiDatabase();
$db->SetLoops(555);
$db->ExecQuasiQuery("SELECT * FROM Table");
//Explain options for rounding the results
echo "Explain options for rounding the results:<BR>";
$tmptimer = new CTimer();
$tmptimer->SetCounting($timer->GetCounting(false));
echo '<CODE>';
echo '<BR>$tmptimer->GetCounting() return ' . $tmptimer->GetCounting();
echo '<BR>$tmptimer->GetCounting(6) return ' . $tmptimer->GetCounting(6);
echo '<BR>$tmptimer->GetCounting(6, false) return ' . $tmptimer->GetCounting(6, false);
echo '<BR>$tmptimer->GetCounting(false) return ' . $tmptimer->GetCounting(false);
echo '</CODE>';
echo '<BR><BR>$tmptimer += 123 seconds:';
$tmptimer->SetCounting($tmptimer->GetCounting(false)+123);
echo '<CODE>';
echo '<BR>$tmptimer->GetCounting() return ' . $tmptimer->GetCounting();
echo '<BR>$tmptimer->GetCounting(6) return ' . $tmptimer->GetCounting(6);
echo '<BR>$tmptimer->GetCounting(6, false) return ' . $tmptimer->GetCounting(6, false);
echo '<BR>$tmptimer->GetCounting(false) return ' . $tmptimer->GetCounting(false);
echo '</CODE>';
//processor wait
$db->SetLoops(631);
$db->ExecQuasiQuery("SELECT * FROM OtherTable");
//processor sleep
usleep(97531);
echo '<BR><BR>Runtime CQuasiDatabase::Query(): ' . $db->GetRuntime() . ' seconds';
echo '<BR>Runtime page: ' . $timer->GetCounting() . ' seconds';
?>
<?php
//class for processor wait
class CQuasiDatabase {
private $Timer;
private $Loops = 1000;
function CQuasiDatabase()
{
$this->Timer = new CTimer(false);
}
function SetLoops($loops)
{
$this->Loops = (int) $loops;
}
function ExecQuasiQuery($quasi_query)
{
$this->Timer->Start();
for($i = 1; $i < $this->Loops; $i++)
{
usleep(258 + strlen($quasi_query)*10);
}
$this->Timer->Stop();
}
function GetRuntime($precision = 3, $cuteRounding = true)
{
return $this->Timer->GetCounting($precision, $cuteRounding);
}
}
?>
|