Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add explicit items()/keys()/values() methods #265

Closed
wants to merge 1 commit into from

Conversation

matthiasdiener
Copy link
Contributor

This appears to speed up these operations substantially.

With this small benchmark:

import immutabledict
import timeit

d_init = {i:i for i in range(10000000)}

d = dict(d_init)
print("dict", timeit.timeit(
    "for k, v in d.items(): s += 1", globals=globals(), number=3, setup="s=0"))

d = immutabledict.immutabledict(d_init)
print("immutabledict", timeit.timeit(
    "for k, v in d.items(): s += 1", globals=globals(), number=3, setup="s=0"))

Before:

$ python dictspeed.py
dict 0.5598837919533253
immutabledict 2.162265417049639

After:

$ python dictspeed.py
dict 0.5607237920630723
immutabledict 0.5689269590564072

The added test fails without this PR.

@corenting
Copy link
Owner

corenting commented Sep 26, 2023

Sorry for the late response and thanks for the MR!

I cherry-picked the commmit in #267 as there were some formatting changes needed. The MR was merged so I'm closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants