public function testMd5Hash() { $hasher = new Flexihash_Md5Hasher(); $result1 = $hasher->hash('test'); $result2 = $hasher->hash('test'); $result3 = $hasher->hash('different'); $this->assertEqual($result1, $result2); $this->assertNotEqual($result1, $result3); // fragile but worthwhile }
public function testHasherSpeed() { $hashCount = 100000; $md5Hasher = new Flexihash_Md5Hasher(); $crc32Hasher = new Flexihash_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; $this->dump(sprintf('Hashers timed over %d hashes (MD5 / CRC32): %f / %f', $hashCount, $timeMd5, $timeCrc32)); }