|
|
|
|
|
|
| |
| <?php
//***************************************************************
//** title : A time measuring and performance benchmarking class.
//**
//** story : Sometimes you need to fine tune your php application
//** or just examine which parts of your code need more
//** time to be executed. This class will help you measure
//** execution times of any block of code you want.
//** You can even stick it in a loop to check whether its
//** iterations require even amounts of cpu time to be
//** executed, in order to spot possible anomalies in your
//** application's execution.
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date : 2005-06-21
//*******************************************************
class Perf {
var $init;
var $count;
var $temp;
//instantiate reader
function Perf() {
$this->init = $this->getmicrotime();
}
//start the clock
function start() {
$this->temp = $this->getmicrotime();
}
//stop the clock
function stop() {
$this->count[] = $this->getmicrotime() - $this->temp;
}
//show results, with a boolean parameter
function printResults($analytical) {
echo "Total execution time " . $this->getSize($this->getmicrotime() - $this->init)."<br/>";
$count = count($this->count);
if ($count==0) return;
$min=$this->count[0];
$max=$this->count[0];
$total=$mini=$maxi=0;
for($i=0; $i<$count; $i++) {
$value = $this->count[$i];
if ($value<$min) {$min = $value; $mini = $i;}
if ($value>$max) {$max = $value; $maxi = $i;}
$total+=$value;
if ($analytical) echo "•iteration #" . ($i+1) . " " . $this->getSize($this->count[$i])."<br/>";
}
echo "Total iterations " . $count . "<br/>";
echo "Average iteration time " . $this->getSize($total/$count)."<br/>";
echo "Min iteration time " . $this->getSize($min) . " on iteration #" . ($mini+1) . "<br/>";
echo "Max iteration time " . $this->getSize($max) . " on iteration #" . ($maxi+1) . "<br/>";
}
//private method to convert milliseconds into something more
//humanly readable
function getSize($size) {
$times = array("msecs", "secs", "mins", "hours", "days", "months", "years");
$divs = array(1000, 60, 60, 24, 30, 12);
$i = 0;
while ($i<count($divs) && $size >= $divs[$i]) {
$size/=$divs[$i];
$i++;
}
return round($size, 4)."Â ".$times[$i];
}
//private method to get the time
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec)*1000;
}
}
//****************************************************
//** An example use of this class
//****************************************************
$perf = new Perf();
for($i=0;$i<10; $i++){
//start counting
$perf->start();
echo "..$i blah blah..".rand();
$x=rand();
if ($i==3) {
for($x=1;$x<12123;$x++){
$y=cos(432);
}
}
$x=$x*rand();
//stop counting
$perf->stop();
}
echo "<hr>";
$perf->printResults(true);
?> | | |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes | | | A Custom Error Handling And Debugging Class Categories : PHP, PHP Classes, Debugging, Errors and Logging | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | [PHP5] PHP Debugger and Helper Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML | | | a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | |
|
|
|