Skip to content

PERF: 30% faster is_period_object checks #33961

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

Merged
merged 1 commit into from
May 4, 2020

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented May 4, 2020

Doing an appropriate isinstance check occurs all in C-space.

In [1]: import pandas as pd                                                                                                                                                   
In [2]: from pandas._libs.lib import *                                                                                                                                        
In [3]: obj = pd.Period(2004, "A")                                                                                                                                            

In [4]: %timeit is_scalar(obj)                                                                                                                                                
78.4 ns ± 0.761 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- PR
101 ns ± 1.74 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- master

In [5]: %timeit is_period(obj)                                                                                                                                                
54.1 ns ± 0.548 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- PR
80.7 ns ± 1.14 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- master

In [6]: %timeit is_period([])                                                                                                                                                 
50.1 ns ± 1.02 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- PR
340 ns ± 26.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # <-- master

In [7]: %timeit is_scalar([])                                                                                                                                                 
65.6 ns ± 0.421 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- PR
67.1 ns ± 0.293 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)  # <-- master

In [8]: obj2 = object()                                                                                                                                                       

In [9]: %timeit is_scalar(obj2)                                                                                                                                               
544 ns ± 6.97 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # <-- PR
782 ns ± 6.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)  # <-- master

@jreback jreback added Performance Memory or execution speed performance Period Period data type labels May 4, 2020
@jreback jreback added this to the 1.1 milestone May 4, 2020
@jreback jreback merged commit c5dad15 into pandas-dev:master May 4, 2020
@jbrockmendel jbrockmendel deleted the perf-isinstance-libs branch May 4, 2020 15:33
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants