Created
September 16, 2014 12:57
-
-
Save olekhy/e0735a82449436db5c8e to your computer and use it in GitHub Desktop.
perfomance testing for generation unique id from string smaller than 1000 chars
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
I've take an simple test for get sure what is the best basic case for this | |
Firstly my timing result: | |
```shell | |
% (php /tmp/testmd5.php); (php /tmp/testsha1.php); (php /tmp/teststr_replace.php); (php /tmp/teststrtr.php); | |
11.715120792389( php /tmp/testmd5.php; ) 11,73s user 0,01s system 99% cpu 11,750 total | |
13.626849889755( php /tmp/testsha1.php; ) 13,65s user 0,00s system 99% cpu 13,653 total | |
16.591732978821( php /tmp/teststr_replace.php; ) 16,60s user 0,02s system 99% cpu 16,627 total | |
87.248502969742( php /tmp/teststrtr.php; ) 87,24s user 0,01s system 99% cpu 1:27,28 total | |
``` | |
**/tmp/testmd5.php** | |
```php | |
$p = '/home/al/p/dimabay/module/DimabayMail/view/dimabay-mail/images/dimabay-card.jpeg'; | |
$t = microtime(1); | |
for ($i=0;$i<10000000;$i++) { | |
$s = md5($p); | |
} | |
$d = microtime(1) - $t; | |
echo $d; | |
``` | |
**/tmp/testsha1.php** | |
```php | |
$p = '/home/al/p/dimabay/module/DimabayMail/view/dimabay-mail/images/dimabay-card.jpeg'; | |
$t = microtime(1); | |
for ($i=0;$i<10000000;$i++) { | |
$s = sha1($p); | |
} | |
$d = microtime(1) - $t; | |
echo $d; | |
``` | |
**/tmp/teststr_replace.php** | |
```php | |
$p = '/home/al/p/dimabay/module/DimabayMail/view/dimabay-mail/images/dimabay-card.jpeg'; | |
$t = microtime(1); | |
for ($i=0;$i<10000000;$i++) { | |
$s = str_replace(['/','-'],'',$p); | |
} | |
$d = microtime(1) - $t; | |
echo $d; | |
``` | |
**/tmp/teststrtr.php** | |
```php | |
$p = '/home/al/p/dimabay/module/DimabayMail/view/dimabay-mail/images/dimabay-card.jpeg'; | |
$t = microtime(1); | |
for ($i=0;$i<10000000;$i++) { | |
$s = strtr($p,['/','-']); | |
} | |
$d = microtime(1) - $t; | |
echo $d; | |
``` | |
hm... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment