]> git.mxchange.org Git - hub.git/blobdiff - contrib/mhash-benchmark.php
moved for later merge to master
[hub.git] / contrib / mhash-benchmark.php
diff --git a/contrib/mhash-benchmark.php b/contrib/mhash-benchmark.php
new file mode 100644 (file)
index 0000000..41061d3
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+error_reporting(0);
+set_time_limit(0);
+
+/*
+ * Note: I could use mhash_count() here but I like to see unavailable hashers
+ * because this is important to me to choose the most-available hasher(s) and
+ * those with the best speed/secure tradeoff.
+ */
+$hasher = array(
+       MHASH_ADLER32,
+       MHASH_CRC32,
+       MHASH_CRC32B,
+       MHASH_GOST,
+       MHASH_HAVAL128,
+       MHASH_HAVAL160,
+       MHASH_HAVAL192,
+       MHASH_HAVAL224,
+       MHASH_HAVAL256,
+       MHASH_MD2,
+       MHASH_MD4,
+       MHASH_MD5,
+       MHASH_RIPEMD128,
+       MHASH_RIPEMD256,
+       MHASH_RIPEMD320,
+       MHASH_SHA1,
+       MHASH_SHA192,
+       MHASH_SHA224,
+       MHASH_SHA256,
+       MHASH_SHA384,
+       MHASH_SHA512,
+       MHASH_SNEFRU128,
+       MHASH_SNEFRU256,
+       MHASH_TIGER,
+       MHASH_TIGER128,
+       MHASH_TIGER160,
+       MHASH_WHIRLPOOL
+);
+
+$timers = array();
+$count = 500 * 1000;
+
+print 'Iterating ' . $count . ' times over all ' . count($hasher) . ' mhash hashers ...' . "\r\n";
+
+foreach ($hasher as $hash) {
+       // Is this no number, the hasher is not available
+       if (!is_int($hash)) {
+               $timers[str_replace('MHASH_', '', $hash)] = '- unavailable -';
+               continue;
+       } // END - if
+
+       $time = microtime(true);
+       for ($idx = 0; $idx <= $count; $idx++) {
+               $dummy = bin2hex(mhash($hash, 'mhash-test-abc-123-foo-bar'));
+       } // END - for
+
+       $timers[mhash_get_hash_name($hash)] = (microtime(true) - $time);
+       print '.';
+} // END - foreach
+
+print "\r\n\r\n";
+asort($timers);
+
+print 'Result from mhash() benchmark (in seconds per hasher):' . "\r\n";
+print_r($timers) . "\n";
+
+?>