Skip to content

Commit e748062

Browse files
authored
Performance compared to uuid1() (#7)
1 parent 9a92a2c commit e748062

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,36 @@ assert my_uuid < uuid7()
9191

9292
This implementation does not include a clock sequence counter as defined in the draft RFC.
9393

94+
## Performance
95+
96+
MacBook Air
97+
```
98+
Python 3.9.7 (default, Oct 12 2021, 22:38:23)
99+
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
100+
Type "help", "copyright", "credits" or "license" for more information.
101+
>>> import timeit
102+
>>> timeit.timeit('uuid1()', number=100000, setup="from uuid import uuid1")
103+
0.14462158300011652
104+
>>> timeit.timeit('uuid6()', number=100000, setup="from uuid6 import uuid6")
105+
0.2687861250000019
106+
>>> timeit.timeit('uuid7()', number=100000, setup="from uuid6 import uuid7")
107+
0.22819437500000106
108+
```
109+
110+
Google [Cloud Shell][cloud shell] VM
111+
```
112+
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
113+
[GCC 8.3.0] on linux
114+
Type "help", "copyright", "credits" or "license" for more information.
115+
>>> import timeit
116+
>>> timeit.timeit('uuid1()', number=100000, setup="from uuid import uuid1")
117+
1.2075679750000745
118+
>>> timeit.timeit('uuid6()', number=100000, setup="from uuid6 import uuid6")
119+
0.6328954440000416
120+
>>> timeit.timeit('uuid7()', number=100000, setup="from uuid6 import uuid7")
121+
0.4709622599998511
122+
```
123+
94124
[ietf draft]: https://github.com/uuid6/uuid6-ietf-draft
95125
[draft 02]: https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-02#section-4.4
126+
[cloud shell]: https://cloud.google.com/shell/docs

src/uuid6/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def unixts(self) -> int:
5252

5353

5454
def _getrandbits(k: int) -> int:
55-
import random
55+
import secrets
5656

57-
return random.SystemRandom().getrandbits(k)
57+
return secrets.randbits(k)
5858

5959

6060
_last_v6_timestamp = None

0 commit comments

Comments
 (0)