note 84394 deleted from function.uniqid by googleguy
| From: | googleguy@php.net | Date: | Tue, 15 Jan 2013 05:08:47 +0000 |
| Subject: | note 84394 deleted from function.uniqid by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193064@lists.php.net to get a copy of this message | ||
Note Submitter: lucas at paivlek dot net
----
Hi all,
I'm not sure what performance problems you guys are talking about, but I benchmarked 10000 of
each of the functions outlined in this comments section alongside the uniqid method. Where function
names are duplicated (because everyone likes to call their method uuid), i've added part of
that contributer's name to the function name.
So if you want something unique and you think that uniqid() is slowing your scripts down, maybe
rand() is your only answer :)
See the output (quickest to slowest):
Array
(
[0] => Array
(
[strMethod] => rand
[intRepetitions] => 10000
[flTotalTime] => 0.104878902435
[flAverageTime] => 1.04878902435E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000297069549561
[exampleOutput] => 19689
)
[1] => Array
(
[strMethod] => uniqid
[intRepetitions] => 10000
[flTotalTime] => 0.123727083206
[flAverageTime] => 1.23727083206E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 9.3936920166E-5
[exampleOutput] => 48782b3c3e997
)
[2] => Array
(
[strMethod] => uniqid2
[intRepetitions] => 10000
[flTotalTime] => 0.132393836975
[flAverageTime] => 1.32393836975E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000135898590088
[exampleOutput] => 48782b3d282c
)
[3] => Array
(
[strMethod] => uuid_mimec
[intRepetitions] => 10000
[flTotalTime] => 0.192065000534
[flAverageTime] => 1.92065000534E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000221014022827
[exampleOutput] => fc1b24b7-59e0-4935-88f2-06a6fde922d8
)
[4] => Array
(
[strMethod] => uuid_maciej
[intRepetitions] => 10000
[flTotalTime] => 0.219671964645
[flAverageTime] => 2.19671964645E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000162839889526
[exampleOutput] => 4c55bc99-b5bc-0f88-0387-00001a51bd33
)
[5] => Array
(
[strMethod] => uuid_dholmes
[intRepetitions] => 10000
[flTotalTime] => 0.221670866013
[flAverageTime] => 2.21670866013E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000198125839233
[exampleOutput] => cd79ac78-af08-a804-6567-3c4940e3252b
)
[6] => Array
(
[strMethod] => newid
[intRepetitions] => 10000
[flTotalTime] => 0.221807956696
[flAverageTime] => 2.21807956696E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000211954116821
[exampleOutput] => user_9e2e305b4c4340397617baf285f11eb348782b3d0354b3.
095706961215834941127.0.0.1
)
[7] => Array
(
[strMethod] => uuid_nodkz
[intRepetitions] => 10000
[flTotalTime] => 0.477306842804
[flAverageTime] => 4.77306842804E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.000205039978027
[exampleOutput] => 0001-7f000001-48782b3e-0952-ef8e7ec8
)
[8] => Array
(
[strMethod] => uuid_lance
[intRepetitions] => 10000
[flTotalTime] => 0.668512821198
[flAverageTime] => 6.68512821198E-5
[flShortestTime] => 3.81469726562E-6
[flLongestTime] => 0.00036096572876
[exampleOutput] => fa465717-26bf-4af9-987f-33bb54905678
)
)