View Single Post
Old 11-28-2007, 07:25 PM   #7 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Right, i just very quickly coded this little test script.
It runs 20 times, then takes the average of 20 iterations.

PHP Code:
<?php


$iterations 
20;
$result 0;

for(
$i 0$i $iterations$i++)
{
    
$test runTest();
    echo 
'<b>Iteration '.($i 1).'</b>: '.$test.'<br />';
    
$result += $test;
    
}
$average = ($result $iterations);

echo 
'<br /><b>Average of '.$iterations.'</b> iterations is '.$average.'<br /> <b>Rounded to 3dp</b> '.round($average3);




function 
runTest()
{
    
$string 'talkphp.com';
    
$loop 30000;
    
$i 0;

    
$time_start microtime(true);


    
//Do While
/*    do
    {
        md5($string);
        //sha1($string);
        $i++;
    }
    while ($i < $loop);*/

    //While
    /*while($i < $loop)
    {
    md5($string);
    //sha1($string);
    }*/
    //For
    /*for ($i = 0; $i < $loop; $i++)
    {
    md5($string);
    //sha1($string);
    }*/


    
$time_end microtime(true);
    
$time = ($time_end $time_start);

    return 
$time;
}
Still seems to show that MD5 is quicker than SHA-1.

just uncomment the type of test u want to run i.e for loop etc.

note because i am running PHP5 i can call microtime(true) because they changed it in php5, in php4 you need something like so:
PHP Code:
function microtime_float()
{
    list(
$usec$sec) = explode(" "microtime());
    return ((float)
$usec + (float)$sec);
}

$time_start microtime_float();

$time_end microtime_float(); 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote