Skip to content

Instantly share code, notes, and snippets.

@predominant
Created March 22, 2010 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save predominant/339799 to your computer and use it in GitHub Desktop.
Save predominant/339799 to your computer and use it in GitHub Desktop.
<?php
$string = uniqid();
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
crc32($string);
}
$elapsed = microtime(true) - $start;
echo "crc32 => $elapsed\n";
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
md5($string);
}
$elapsed = microtime(true) - $start;
echo "md5 => $elapsed\n";
$start = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
sha1($string);
}
$elapsed = microtime(true) - $start;
echo "sha1 => $elapsed\n";
/**
* A note for benchmark vampires:
*
* For the love of God, don't compare PHP versions to each other.
* Yes, benchmarks such, but within a single sample set on any
* machine, you can test the speed of each of these operations
* against each other. Its not designed or intended to compare
* the speed between PHP versions.
*/
/**
* Result
* --------------------
* PHP v5.3.0
*
* crc32 => 0.30762314796448
* md5 => 0.93620681762695
* sha1 => 0.8613178730011
*/
/**
* Result
* --------------------
* PHP v5.2.13
*
* crc32 => 0.295562982559
* md5 => 0.840898990631
* sha1 => 0.810412883759
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment