Skip to content

Improve perfomance of UUID.hex and UUID.__str__ by using bytes.hex() #131196

Description

@booqoffsky

Feature or enhancement

Proposal:

In my tests, using bytes.hex() speeds up calling the UUID.hex property.

Additionally, using the hex property and f-strings also provides some speedup in calling uuid.UUID.str.

import uuid

uuids = [uuid.uuid4() for _ in range(100000)]

t1 = time.monotonic()
for u in uuids:
    u.hex
    # str(u)
t2 = time.monotonic()

print(t2 - t1)

Results before and after the fix:

hex
before: 0.021755493999989994
after:  0.01465080400066654 

str
before: 0.06381790500017814
after:  0.05134949700004654

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions