1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans nom</title>
</head>
<body>
<?php
class bench
{
// Contient les différents temps pour les étapes
var $data = array();
// Temps final
var $end = 0;
// Temps de départ
var $start = 0;
/*
** Constructeur de la classe bench.
** Initialise le temps de départ.
*/
function bench()
{
$this->start = $this->get_time();
}
/*
** Créé un marqueur qui retient le temps écoulé.
** -----
** $name :: Nom du marqueur.
*/
function set_mark($name)
{
$this->data[] = array('name' => $name, 'time' => $this->get_time());
}
/*
** Sauvegarde le temps final et affiche tous les temps des marqueurs,
** avec un certain nombre de statistique.
*/
function finish()
{
$this->end = $this->get_time();
$total = $this->end - $this->start;
echo '
<table width="800" align="center" style="border: solid 1px #000000;">
<tr>
<td style="background-color: #cccccc; font-weight: bold; text-align: center;" colspan="4">Benchmark</td>
</tr>
<tr>
<td style="background-color: #dddddd; width: 400px; text-align: center;" colspan="2">Temps d\'éxécution total :</td>
<td style="background-color: #eeeeee; text-align: center;" colspan="2">' . ($total) . '</td>
</tr>
<tr>
<td style="background-color: #cccccc; font-weight: bold; text-align: center;" colspan="4">Marqueurs</td>
</tr>
<tr>
<td style="background-color: #dddddd; width: 200px; text-align: center; font-weight: bold;">Nom du marqueur</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center; font-weight: bold;">Temps du marqueur</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center; font-weight: bold;">Temps passé</td>
<td style="background-color: #dddddd; width: 200px; text-align: center; font-weight: bold;">Pourcentage d\'éxécution</td>
</tr>
<tr>
<td style="background-color: #dddddd; width: 200px; text-align: center;">Temps de départ :</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . ($this->start) . '</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . (0) . '</td>
<td style="background-color: #dddddd; width: 200px; text-align: center;">0%</td>
</tr>
';
foreach ($this->data AS $v)
{
$time_added = $v['time'] - $this->start;
$percent = ($time_added / $total) * 100;
echo '
<tr>
<td style="background-color: #dddddd; width: 200px; text-align: center;">Marqueur ' . $v['name'] . ' :</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . ($v['time']) . '</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . ($time_added) . '</td>
<td style="background-color: #dddddd; width: 200px; text-align: center;">' . round($percent) . '%</td>
</tr>
';
$before = $v['time'];
}
echo '
<tr>
<td style="background-color: #dddddd; width: 200px; text-align: center;">Temps d\'arrivé :</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . ($this->end) . '</td>
<td style="background-color: #eeeeee; width: 200px; text-align: center;">' . ($total) . '</td>
<td style="background-color: #dddddd; width: 200px; text-align: center;">100%</td>
</tr>
</table>
';
}
/*
** Renvoie un temps pour le benchmark.
*/
function get_time()
{
$ary = explode(' ', microtime());
return ($ary[0] + $ary[1]);
}
}
?>
</body>
</html> |