Location: PHPKode > scripts > Chrono Class > chrono-class/chrono.example.php
<?php
include("./chrono.class.php");

##################################################################################
# Function: delay                                                Date: 09-Apr-2002
# Author: Ariel Filipiak <hide@address.com>
#            This code is released under GPL (GNU Public License)                
# Feel free to edit/use so long as you keep this copyright.USE at your own risk! 

function delay($i_sec = 0) {
    $ts_now = explode(" ", microtime()); 
    $ts_ini = $ts_now[1] + $ts_now[0];
    for ($ts_clock = $ts_ini; $ts_clock <= ($ts_ini + $i_sec); $ts_clock) {
        $ts_now = explode(" ", microtime()); 
        $ts_clock = $ts_now[1] + $ts_now[0];
    }
}

##################################################################################
# Aux functions

function printIniTB($s_title) {
    
    echo "<table border=1 cellpadding=2 cellspacing=0 bordercolor=DEDEDE>\n";
    echo "<tr><td colspan=4 align=center><b>Example $s_title</b></td></tr>\n";
    echo "<tr><td><b>action</b></td><td><b>print</b></td>";
    echo "<td><b>\$clock->run</b></td><td><b>\$clock->time</b></td></tr>\n";
}

function printDelay($i_sec) {
    
    echo "<tr><td colspan=4 align=center><i>Delay $i_sec sec</i></td></tr>\n";
    delay($i_sec);
}

function printEndRow() {
    global $clock;
    
    echo "</td><td align=center>".($clock->run ? "TRUE" : "FALSE");
    echo "</td><td align=right>".$clock->time."</td></tr>\n";
}

##################################################################################
# Print Examples

echo "<style>\ntd { font : 9pt Arial, Helvetica, Helv, sans-serif; }</style>\n";
echo "<center><br>";

printIniTB("1: SIMPLE");
echo "<tr><td>\$clock = new chrono;</td><td>"; $clock = new chrono; printEndRow();
printDelay(0.01);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
echo "</table><br>";

printIniTB("2: START, STOP & RESTART");
echo "<tr><td>\$clock = new chrono(\"%01.2f\");</td><td>"; $clock = new chrono("%01.2f"); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->start();</td><td>"; echo $clock->start(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->start();</td><td>"; echo $clock->start(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->restart();</td><td>"; echo $clock->restart(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
echo "</table><br>";

printIniTB("3: LAP");
echo "<tr><td>\$clock = new chrono(\"%01.2f\");</td><td>"; $clock = new chrono("%01.2f"); printEndRow();
printDelay(0.02);
echo "<tr><td colspan=4 align=center><b>STOP/STOP BAD FORM</b></td></tr>\n";
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
echo "<tr><td colspan=4 align=center><b>CORRECT FORM</b></td></tr>\n";
echo "<tr><td>\$clock = new chrono(\"%01.2f\");</td><td>"; $clock = new chrono("%01.2f"); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->lap();</td><td>"; echo $clock->lap(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->start();</td><td>"; echo $clock->start(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->lap();</td><td>"; echo $clock->lap(); printEndRow();
printDelay(0.02);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
echo "</table><br>";


printIniTB("4: MEM & GETMEM (MEMKEY & MEMLAP)");
echo "<tr><td>\$clock = new chrono(\"%01.2f\");</td><td>"; $clock = new chrono("%01.2f"); printEndRow();
printDelay(0.04);
echo "<tr><td>echo \$clock->mem(\"one\");</td><td>"; echo $clock->mem("one"); printEndRow();
printDelay(0.04);
echo "<tr><td>echo \$clock->lap(\"one\");</td><td>"; echo $clock->lap("one"); printEndRow();
echo "<tr><td>echo \$clock->lap();</td><td>"; echo $clock->lap(); printEndRow();
echo "<tr><td>echo \$clock->mem(\"two\");</td><td>"; echo $clock->mem("two"); printEndRow();
printDelay(0.04);
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.04);
echo "<tr><td>echo \$clock->start();</td><td>"; echo $clock->start(); printEndRow();
echo "<tr><td>echo \$clock->lap(\"two\");</td><td>"; echo $clock->lap("two"); printEndRow();
echo "<tr><td>echo \$clock->lap(\"one\");</td><td>"; echo $clock->lap("one"); printEndRow();
echo "<tr><td>echo \$clock->lap();</td><td>"; echo $clock->lap(); printEndRow();
echo "<tr><td>echo \$clock->getmem();</td><td>"; echo $clock->getmem(); echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memkey[0];</td><td>"; echo $clock->memkey[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[0];</td><td>"; echo $clock->memlap[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memkey[1];</td><td>"; echo $clock->memkey[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[1];</td><td>"; echo $clock->memlap[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->stop();</td><td>"; echo $clock->stop(); printEndRow();
printDelay(0.06);
echo "<tr><td>echo \$clock->getmem();</td><td>"; echo $clock->getmem(); printEndRow();
echo "<tr><td>echo \$clock->memkey[0];</td><td>"; echo $clock->memkey[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[0];</td><td>"; echo $clock->memlap[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memkey[1];</td><td>"; echo $clock->memkey[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[1];</td><td>"; echo $clock->memlap[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->start();</td><td>"; echo $clock->start(); printEndRow();
printDelay(0.06);
echo "<tr><td>echo \$clock->getmem();</td><td>"; echo $clock->getmem(); printEndRow();
echo "<tr><td>echo \$clock->memkey[0];</td><td>"; echo $clock->memkey[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[0];</td><td>"; echo $clock->memlap[0]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memkey[1];</td><td>"; echo $clock->memkey[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "<tr><td>echo \$clock->memlap[1];</td><td>"; echo $clock->memlap[1]; echo "<td colspan=2>&nbsp; &nbsp;</tD></tr>";
echo "</table><br>";

?>
Return current item: Chrono Class