Created
June 28, 2011 21:26
-
-
Save soldair/1052268 to your computer and use it in GitHub Desktop.
fastest way to get a hash based on the githash in php
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 | |
/* | |
~>php bench.php | |
md5_file 634.3932 ms | |
hash_file/md5 714.4802 ms | |
parse contents 911.6130 ms | |
parse contents substr 852.8361 ms | |
contents first chunk 590.0660 ms | |
all ran with 30000 itterations | |
*/ | |
$t = microtime(true); | |
for($i = 0;$i<30000;$i++) { | |
md5_file('api/.git/FETCH_HEAD'); | |
} | |
echo sprintf('md5_file %0.4f ms',(microtime(true)-$t)*1000)."\n"; | |
$t = microtime(true); | |
for($i = 0;$i<30000;$i++) { | |
hash_file('md5','api/.git/FETCH_HEAD'); | |
} | |
echo sprintf('hash_file/md5 %0.4f ms',(microtime(true)-$t)*1000)."\n"; | |
$t = microtime(true); | |
for($i = 0;$i<30000;$i++) { | |
current(explode("\t",file_get_contents('api/.git/FETCH_HEAD'))); | |
} | |
echo sprintf('explode contents %0.4f ms',(microtime(true)-$t)*1000)."\n"; | |
$t = microtime(true); | |
for($i = 0;$i<30000;$i++) { | |
$str = file_get_contents('api/.git/FETCH_HEAD'); | |
substr($str,0,strpos($str,"\t")); | |
} | |
echo sprintf('parse contents substr %0.4f ms',(microtime(true)-$t)*1000)."\n"; | |
$t = microtime(true); | |
for($i = 0;$i<30000;$i++) { | |
file_get_contents('api/.git/FETCH_HEAD',false,null,-1,40); | |
} | |
echo sprintf('contents first chunk %0.4f ms',(microtime(true)-$t)*1000)."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$t = microtime(true);
for($i = 0;$i<30000;$i++) {
on my system 28.3351 ms