linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file class.bench.php

Documentation is available at class.bench.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage system
  5.  * @author fablezouave modified by linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  * @link http://classes.scriptsphp.org/doc.bench
  10.  *  Bench Tool
  11.  */
  12.  
  13. class bench {
  14.  
  15.   var $start;
  16.   var $decimals;
  17.   var $Result;
  18.  
  19.   /*
  20.    Constructeur de la classe
  21.    (initialisation des variables)
  22.    */
  23.  
  24.   function bench({
  25.  
  26.     $this->start = 0;
  27.     // Nombre de chiffres après la virgule
  28.     // pour l' affichage des résultats
  29.     $this->decimals = 10;
  30.     $this->Result = array();
  31.   }
  32.  
  33.   /*
  34.    Cette méthode marque le début du benchmark
  35.    */
  36.  
  37.   function start_bench({
  38.     $this->start = bench::get_microtime();
  39.   }
  40.  
  41.   /*
  42.    Cette méthode marque la fin du benchmark
  43.    */
  44.  
  45.   function end_bench({
  46.     $end bench::get_microtime($this->start;
  47.     $this->Result['End'$end;
  48.   }
  49.  
  50.  
  51.   /*
  52.    Cette méthode sert à récupérer
  53.    des temps intermèdiaires
  54.    */
  55.  
  56.   function add_flag($txt{
  57.     $flag bench::get_microtime($this->start;
  58.     $this->Result[$txt$flag;
  59.   }
  60.  
  61.   /*
  62.    Cette méthode retourne un temps exploitable.
  63.    */
  64.  
  65.   function get_microtime(){
  66.     $T explode(' 'microtime());
  67.     $time $T[1].substr($T[0]1);
  68.     return (float)$time;
  69.   }
  70.  
  71.   /*
  72.    Cette méthode retourne le nombre $value
  73.    formaté avec n chiffres après la virgule
  74.    */
  75.  
  76.   function format($value$n=0{
  77.     $dec $n==$this->decimals : $n;
  78.     return number_format((float)$value$dec);
  79.   }
  80.  
  81.   /*
  82.    Cette méthode retourne le résultat des benchs
  83.    sous la forme d' un tableau HTML.
  84.    */
  85.  
  86.   function return_result({
  87.     $prec  0;
  88.     $inter 0;
  89.  
  90.     $ret  '<table style="border:1px solid #666;">';
  91.     $ret .= '<tr style="background-color:#cccccc;color:#333">';
  92.     $ret .= '<td>Event</td>';
  93.     $ret .= '<td>Time from the beginning</td>';
  94.     $ret .= '<td>Time from last flag</td>';
  95.     $ret .= '<td> - Percentage -</td>';
  96.     $ret .= '</tr>';
  97.  
  98.     foreach($this->Result as $key => $val{
  99.       $inter $val $prec;
  100.       $prec $val;
  101.       $percent ($inter/$this->Result['End'])*100;
  102.  
  103.       $ret .= '<tr>';
  104.       $ret .= '<td>'.$key.'</td>';
  105.       $ret .= '<td>'.bench::format($val).' s</td>';
  106.       $ret .= '<td>'.bench::format($inter).' s</td>';
  107.       $ret .= '<td>'.bench::format($percent2).' % </td>';
  108.       $ret .= '</tr>';
  109.     }
  110.  
  111.     $ret .= '</table>';
  112.  
  113.     return $ret;
  114.   }
  115.  
  116.   /*
  117.    Cette méthode retourne un simple résultat
  118.    correspondant au temps passé entre
  119.    start_bench() et end_bench()
  120.    */
  121.  
  122.   function return_simple_result({
  123.     $r bench::format($this->Result['End'];
  124.     $ret "Page générée en $r secondes. / Generated in $r seconds";
  125.     return $ret;
  126.   }
  127.  
  128.  
  129. // end class
  130.  
  131. ?>

Documentation generated on Fri, 16 Oct 2009 09:29:04 +0200 by phpDocumentor 1.4.1