<?php
// Settings
$numbStrings 10000;
$stringLength 50;
$asciiValue = array('min' => 32,
                    
'max' => 126);
// Creating random strings;
$randStrings = array();
for (
$i 1$i <= $numbStrings$i++) {
    
$randString "";
    for (
$m 1$m <= $stringLength$m++) {
        
$randString .= chr(rand($asciiValue['min'], $asciiValue['max']));
    }
    
$randStrings[] = $randString;
}
function 
timeAction($title$evalCode$randStrings) {
    
$timerStart explode(' 'microtime());
    
$timerStart $timerStart[1] + $timerStart[0];
    foreach (
$randStrings as $randString) {
        eval(
$evalCode);
    }
    
$timerEnd explode(' 'microtime());
    
$timerEnd $timerEnd[1] + $timerEnd[0];
    
$time $timerEnd $timerStart;
    return array(
'type' => $title'time' => $time);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Timing</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" type="text/css" media="screen" href="http://www.e-x-e.dk/labs/tools/assets/style.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="http://e-x-e.dk/labs/portfolio/assets/css/screen.css" />
</head>
<body>
<!-- Container -->
<div class="container">
    <!-- Content Background -->
    <div id="background"></div>

    <!-- Content -->
    <div class="content">
        <!-- Main Content -->
            <div class="main-content" style="overflow:scroll">
            <?php
            
echo 'Number of strings: ' $numbStrings '<br />';
            echo 
'String length: ' $stringLength '<br />';
            
?>
            <table>
                <thead>
                    <tr>
                        <th style="width: 100px">Type</th>
                        <th style="width: 300px">Total time [seconds]</th>
                        <th style="width: 300px">Time per password [microseconds]</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $timingArray 
= array();
                    foreach (
hash_algos() as $algorithm) {
                        
$result timeAction($algorithm'hash(\'' $algorithm '\',$randString);'$randStrings);
                        
$timingArray[$result['type']] = $result['time'];
                    }
                    
asort($timingArray);
                    foreach (
$timingArray as $type => $time) {
                        echo 
'<tr>';
                        echo 
'<td>' $type '</td>';
                        echo 
'<td>' $time '</td>';
                        echo 
'<td>' . ($time/$numbStrings)*1000000 '</td>';
                        echo 
'</tr>';
                    }
                    
?>
                </tbody>
            </table>
            </div>
        <!-- //Main Content -->

    </div>
    <!-- //Content -->

</div>
<!-- //Container -->
</body>
</html>