Created
March 31, 2017 17:49
-
-
Save pranavgarg/b0003163fbfad0bc6275e9287b9e7d35 to your computer and use it in GitHub Desktop.
performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$loops = 100000; | |
$str = "ana are mere"; | |
echo "<pre>"; | |
$tss = microtime(true); | |
for($i=0; $i<$loops; $i++){ | |
$x = crc32($str); | |
} | |
$tse = microtime(true); | |
echo "\ncrc32: \t" . round($tse-$tss, 5) . " \t" . $x; | |
$tss = microtime(true); | |
for($i=0; $i<$loops; $i++){ | |
$x = md5($str); | |
} | |
$tse = microtime(true); | |
echo "\nmd5: \t".round($tse-$tss, 5) . " \t" . $x; | |
$tss = microtime(true); | |
for($i=0; $i<$loops; $i++){ | |
$x = rand(); | |
} | |
$tse = microtime(true); | |
echo "\nrand: \t".round($tse-$tss, 5) . " \t" . $x; | |
$tss = microtime(true); | |
for($i=0; $i<$loops; $i++){ | |
$l = strlen($str); | |
$x = 0x77; | |
for($j=0;$j<$l;$j++){ | |
$x = $x xor ord($str[$j]); | |
} | |
} | |
$tse = microtime(true); | |
echo "\nxor: \t".round($tse-$tss, 5) . " \t" . $x; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment