Last active
July 14, 2024 21:33
-
-
Save ulgens/a17dc91e314f790fa44d11f3e0debab8 to your computer and use it in GitHub Desktop.
Compare UUID7 generation speed of different packages
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
# This script can be easily run with the following command: | |
# $ hatch run uuid7_generation_speed.py | |
# or you can manually install the dependencies and run the script as you like. | |
# | |
# https://github.com/pypa/hatch/blob/master/docs/how-to/run/python-scripts.md | |
# | |
# /// script | |
# title = "Performance test for UUID7 generators" | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "uuid-utils==0.9.0", | |
# "uuid7==0.1.0", | |
# ] | |
# /// | |
import time | |
from uuid_extensions import uuid7 as extensions_uuid7 # https://github.com/stevesimmons/uuid7 | |
from uuid_utils import uuid7 as utils_uuid7 # https://github.com/aminalaee/uuid-utils | |
NUM_ITERATIONS = 1_000_000 | |
def test_uuid_utils(): | |
""" | |
Test the performance of uuid_utils.uuid7(), Rust implementation | |
""" | |
start_time = time.time() | |
for _ in range(NUM_ITERATIONS): | |
utils_uuid7() | |
print("--- %s seconds ---" % (time.time() - start_time)) | |
def test_uuid_extensions(): | |
""" | |
Test the performance of uuid_utils.uuid7(), Python implementation | |
""" | |
start_time = time.time() | |
for _ in range(NUM_ITERATIONS): | |
extensions_uuid7() | |
print("--- %s seconds ---" % (time.time() - start_time)) | |
if __name__ == "__main__": | |
test_uuid_utils() | |
test_uuid_extensions() | |
# Test conditions: Macbook Pro with Apple M1 Pro chip, Python 3.12.4 | |
# For 1_000_000 iterations: | |
# * uuid_utils: 0.11 seconds | |
# * uuid_extensions: 1.55 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment