| 
<!DOCTYPE html><html>
 <head>
 <title>Luhn's algorithm speed test</title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 </head>
 <body>
 <div>
 <pre>
 <?php
 include_once 'Luhn.php';
 $luhn = new Luhn();
 
 // New method, see http://www.phpclasses.org/discuss/package/8471/thread/1/
 $startTime = microtime(true);
 $number = "38972438297432";
 for($i = 0; $i < 1000000; $i++){
 $checkDigit = $luhn->calculate($number.$i);
 }
 $endTime = microtime(true);
 echo "time1: ".($endTime - $startTime)." sec\n";
 
 // Old method
 $startTime = microtime(true);
 $number = "38972438297432";
 for($i = 0; $i < 1000000; $i++){
 $checkDigit = $luhn->calculateOld($number.$i);
 }
 $endTime = microtime(true);
 echo "time2: ".($endTime-$startTime)." sec\n";
 ?>
 </pre>
 </div>
 </body>
 </html>
 |