note 84394 added to function.uniqid
| From: | lucas at paivlek dot net | Date: | Sat, 12 Jul 2008 04:07:03 +0000 |
| Subject: | note 84394 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141419@lists.php.net to get a copy of this message | ||
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
)
)
----
Server IP: 117.104.160.194
Probable Submitter: 58.160.105.78
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/84394
Del: integrated -- https://master.php.net/note/delete/84394/integrated
Del: useless -- https://master.php.net/note/delete/84394/useless
Del: bad code -- https://master.php.net/note/delete/84394/bad+code
Del: spam -- https://master.php.net/note/delete/84394/spam
Del: non-english -- https://master.php.net/note/delete/84394/non-english
Del: in docs -- https://master.php.net/note/delete/84394/in+docs
Del: other reasons-- https://master.php.net/note/delete/84394
Reject -- https://master.php.net/note/reject/84394
Search -- https://master.php.net/manage/user-notes.php