Source for file benchmark.php
Documentation is available at benchmark.php
require_once '../Matrix.php';
require_once 'Stats.php';
* Example of use of Matrix Class, featuring magic squares.
* Simple function to replicate PHP 5 behaviour
return ((float) $usec + (float) $sec);
} // function microtime_float()
$this->stat->setData($times);
$stats = $this->stat->calcFull();
echo '<table style="margin-left:32px;">';
echo '<tr><td style="text-align:right;"><b>n:</b><td style="text-align:right;">' . $stats['count'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>Mean:</b><td style="text-align:right;">' . $stats['mean'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>Min.:</b><td style="text-align:right;">' . $stats['min'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>Max.:</b><td style="text-align:right;">' . $stats['max'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>σ:</b><td style="text-align:right;">' . $stats['stdev'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>Variance:</b><td style="text-align:right;">' . $stats['variance'] . ' </td></tr>';
echo '<tr><td style="text-align:right;"><b>Range:</b><td style="text-align:right;">' . $stats['range'] . ' </td></tr>';
} // function displayStats()
function runEig($n = 4, $t = 100) {
for ($i = 0; $i < $t; ++ $i) {
$M = Matrix::random($n, $n);
$times[] = $stop_time - $start_time;
function runLU($n = 4, $t = 100) {
for ($i = 0; $i < $t; ++ $i) {
$M = Matrix::random($n, $n);
$E = new LUDecomposition($M);
$times[] = $stop_time - $start_time;
function runQR($n = 4, $t = 100) {
for ($i = 0; $i < $t; ++ $i) {
$M = Matrix::random($n, $n);
$E = new QRDecomposition($M);
$times[] = $stop_time - $start_time;
for ($i = 0; $i < $t; ++ $i) {
$M = Matrix::random($n, $n);
$times[] = $stop_time - $start_time;
} // function runCholesky()
function runSVD($n = 4, $t = 100) {
for ($i = 0; $i < $t; ++ $i) {
$M = Matrix::random($n, $n);
$times[] = $stop_time - $start_time;
echo "<b>Cholesky decomposition: $t random {$n}x{$n} matrices</b><br />";
echo "<b>Eigenvalue decomposition: $t random {$n}x{$n} matrices</b><br />";
echo "<b>LU decomposition: $t random {$n}x{$n} matrices</b><br />";
echo "<b>QR decomposition: $t random {$n}x{$n} matrices</b><br />";
echo "<b>Singular Value decomposition: $t random {$n}x{$n} matrices</b><br />";
} // function Benchmark()
} // class Benchmark (end MagicSquareExample)
switch($_REQUEST['decomposition']) {
for ($i = 2; $i <= 8; $i *= 2) {
echo "<b>Cholesky decomposition: $t random {$i}x{$i} matrices</b><br />";
foreach($m as $x => $y) {
echo "$x\t" . 1000* $y . "\n";
for ($i = 2; $i <= 8; $i *= 2) {
echo "<b>Eigenvalue decomposition: $t random {$i}x{$i} matrices</b><br />";
foreach($m as $x => $y) {
echo "$x\t" . 1000* $y . "\n";
for ($i = 2; $i <= 8; $i *= 2) {
echo "<b>LU decomposition: $t random {$i}x{$i} matrices</b><br />";
foreach($m as $x => $y) {
echo "$x\t" . 1000* $y . "\n";
for ($i = 2; $i <= 8; $i *= 2) {
echo "<b>QR decomposition: $t random {$i}x{$i} matrices</b><br />";
foreach($m as $x => $y) {
echo "$x\t" . 1000* $y . "\n";
for($i = 2; $i <= 8; $i *= 2) {
echo "<b>Singular value decomposition: $t random {$i}x{$i} matrices</b><br />";
foreach($m as $x => $y) {
echo "$x\t" . 1000* $y . "\n";
print ("<br /><b>Total<b>: {$s}s<br />");
<li><a href="benchmark.php?decomposition=all">Complete Benchmark</a>
<li><a href="benchmark.php?decomposition=cholesky">Cholesky</a></li>
<li><a href="benchmark.php?decomposition=eigenvalue">Eigenvalue</a></li>
<li><a href="benchmark.php?decomposition=lu">LU</a></li>
<li><a href="benchmark.php?decomposition=qr">QR</a></li>
<li><a href="benchmark.php?decomposition=svd">Singular Value</a></li>
|