Skip to content

Instantly share code, notes, and snippets.

@pranavgarg
Created March 31, 2017 17:49
Show Gist options
  • Save pranavgarg/b0003163fbfad0bc6275e9287b9e7d35 to your computer and use it in GitHub Desktop.
Save pranavgarg/b0003163fbfad0bc6275e9287b9e7d35 to your computer and use it in GitHub Desktop.
performance
<?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