Example #1
0
 public function testMd5Hash()
 {
     $hasher = new Md5Hasher();
     $result1 = $hasher->hash('test');
     $result2 = $hasher->hash('test');
     $result3 = $hasher->hash('different');
     $this->assertEquals($result1, $result2);
     $this->assertNotEquals($result1, $result3);
     // fragile but worthwhile
 }
Example #2
0
 public function testHasherSpeed()
 {
     $hashCount = 100000;
     $md5Hasher = new Md5Hasher();
     $crc32Hasher = new Crc32Hasher();
     $start = microtime(true);
     for ($i = 0; $i < $hashCount; $i++) {
         $md5Hasher->hash("test{$i}");
     }
     $timeMd5 = microtime(true) - $start;
     $start = microtime(true);
     for ($i = 0; $i < $hashCount; $i++) {
         $crc32Hasher->hash("test{$i}");
     }
     $timeCrc32 = microtime(true) - $start;
     echo sprintf("\nHashers timed over %d hashes (MD5 / CRC32): %f / %f \n", $hashCount, $timeMd5, $timeCrc32);
 }