PHP Classes

File: testCTimer.php

Recommend this page to a friend!
  Classes of Pavel Astakhov   CTimer   testCTimer.php   Download  
File: testCTimer.php
Role: Example script
Content type: text/plain
Description: Example script
Class: CTimer
Measure the time elapsed during PHP execution
Author: By
Last change:
Date: 14 years ago
Size: 2,256 bytes
 

Contents

Class file image Download
<?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() &nbsp; &nbsp; &nbsp; &nbsp; return ' . $tmptimer->GetCounting();
echo
'<BR>$tmptimer->GetCounting(6) &nbsp; &nbsp; &nbsp;&nbsp; return ' . $tmptimer->GetCounting(6);
echo
'<BR>$tmptimer->GetCounting(6, false) return ' . $tmptimer->GetCounting(6, false);
echo
'<BR>$tmptimer->GetCounting(false) &nbsp; &nbsp;return ' . $tmptimer->GetCounting(false);
echo
'</CODE>';

echo
'<BR><BR>$tmptimer += 123 seconds:';
$tmptimer->SetCounting($tmptimer->GetCounting(false)+123);
echo
'<CODE>';
echo
'<BR>$tmptimer->GetCounting() &nbsp; &nbsp; &nbsp; &nbsp; return ' . $tmptimer->GetCounting();
echo
'<BR>$tmptimer->GetCounting(6) &nbsp; &nbsp; &nbsp;&nbsp; return ' . $tmptimer->GetCounting(6);
echo
'<BR>$tmptimer->GetCounting(6, false) return ' . $tmptimer->GetCounting(6, false);
echo
'<BR>$tmptimer->GetCounting(false) &nbsp; &nbsp;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);
  }
}

?>