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

Drop to_pickable()/from_pickable() helpers #667

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

skirpichev
Copy link
Collaborator

@skirpichev skirpichev commented Mar 26, 2023

Without gmpy2:

    >>> import mpmath, pickle
    >>> pi = mpmath.pi
    >>> mpmath.mp.dps=100
    >>> a = mpmath.mpf(pi)
    >>> len(pickle.dumps(a))  # vs 147
    105

Fixes #440

  • test speed

@skirpichev
Copy link
Collaborator Author

With gmpy2:

# on the master:
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import dumps' 'dumps(a)'
10000 loops, best of 10: 21.3 usec per loop
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import loads,dumps;b=dumps(a)' 'loads(b)'
10000 loops, best of 10: 24.6 usec per loop
# on this branch:
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import dumps' 'dumps(a)'
10000 loops, best of 10: 27.7 usec per loop
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import loads,dumps;b=dumps(a)' 'loads(b)'
10000 loops, best of 10: 25.1 usec per loop

Without:

# on the master:
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import dumps' 'dumps(a)'
20000 loops, best of 10: 19.8 usec per loop
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import loads,dumps;b=dumps(a)' 'loads(b)'
10000 loops, best of 10: 21.5 usec per loop
# on this branch:
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import dumps' 'dumps(a)'
20000 loops, best of 10: 14.5 usec per loop
$ python -m timeit -r10 -s 'from mpmath import mp,pi,mpf;mp.dps=100;a=mpf(pi)' \
    -s 'from pickle import loads,dumps;b=dumps(a)' 'loads(b)'
20000 loops, best of 10: 18.5 usec per loop

Without gmpy2:
    >>> import mpmath, pickle
    >>> pi = mpmath.pi
    >>> mpmath.mp.dps=100
    >>> a = mpmath.mpf(pi)
    >>> len(pickle.dumps(a))  # vs 147
    105

Fixes mpmath#440
@skirpichev skirpichev merged commit 21fe1e6 into mpmath:master Sep 5, 2023
7 checks passed
@skirpichev skirpichev deleted the fix-440-pickle branch September 5, 2023 04:28
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.

to_pickable/from_pickable may be obsoleted or may be more simple
2 participants