Skip to content

Conversation

@groutr
Copy link
Contributor

@groutr groutr commented Aug 24, 2018

Previously, assoc would call factory(), add a single key-value pair and then call merge. Merge would then call factory() again and update the mapping with both the original mapping and the single element mapping.

This version avoids calling merge for updating a single value in the mapping (with only a single call to factory()).

# len(a) == 10
In [6]: %timeit assoc(a, 'key', '42')
1.71 µs ± 92.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [7]: %timeit assoc1(a, 'key', '42')
768 ns ± 12.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

# len(b) == 1000
In [8]: %timeit assoc(b, 'key', '42')
25.6 µs ± 932 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [9]: %timeit assoc1(b, 'key', '42')
24.4 µs ± 862 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

# len(c) == 10000
In [10]: %timeit assoc(c, 'key', '42')
269 µs ± 7.74 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [11]: %timeit assoc1(c, 'key', '42')
265 µs ± 5.65 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

@groutr
Copy link
Contributor Author

groutr commented Oct 8, 2018

ping @eriknw

@eriknw eriknw merged commit 062786a into pytoolz:master Oct 8, 2018
@eriknw
Copy link
Member

eriknw commented Oct 8, 2018

Thanks for all your attention recently @groutr! Sorry for my absence. "Real Life" has been very busy.

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