Login   Register  
PHP Classes
elePHPant
Icontem

File: test_05_benchmark.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of n/a  >  Cache output and objects  >  test_05_benchmark.php  >  Download  
File: test_05_benchmark.php
Role: Example script
Content type: text/plain
Description: Benchmark example
Class: Cache output and objects
Cache the output of PHP scripts in files
Author: By
Last change:
Date: 7 years ago
Size: 1,512 bytes
 

Contents

Class file image Download
<?

/*
This examle shows why cacheing is important...
You shuld cache your data when doing complex math calculations,
executing many database querys or taking too many processor time
on server for any reason.
*/

require_once("cache.php");

$path ".";
$cache = new Cache($path);

$time microtime_float();

while(
$cache->save("cache.test_05.tmp",10))
{
    
$pi bcpi(40);
    echo(
"<b>pi = ".$pi."</b><br><br>");
    echo(
"<b>This part is executed every 10 seconds</b><br>");
    echo(
"<b>Time of execution: <u>".(microtime_float() - $time)." s</u></b><br><br>");
}

echo(
"<b>This part is executed every time</b><br>");
echo(
"<b>Script time of execution: <u>".(microtime_float() - $time)." s</u></b><br><br>");



// helper functions...............................

function microtime_float()
{
   list(
$usec$sec) = explode(" "microtime());
   return ((float)
$usec + (float)$sec);
}


function 
bcpi($precision=30){
        
$accuracy = ($precision+5)*45/32;
    
//accuracy worked till the 180th $precision, almost used 30 second to calculate
        
bcscale($precision+5);
        
$n 1;
        
$bcatan1 0;
        
$bcatan2 0;
        while(
$n $accuracy){
    
//atan functions
            
$bcatan1 bcadd($bcatan1bcmul(bcdiv(pow(-1$n+1), $n 1), bcpow(0.2$n -1)));
            
$bcatan2 bcadd($bcatan2bcmul(bcdiv(pow(-1$n+1), $n 1), bcpow(bcdiv(1,239), $n -1)));
            ++
$n;
        }
    return  
bcmul(4,bcsub(bcmul(4$bcatan1),$bcatan2),5);
}


?>