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

PERF: use arr.size instead of np.prod(arr.shape) in _can_use_numexpr #39825

Conversation

jorisvandenbossche
Copy link
Member

xref #39772

Using np.prod gives quite some overhead, and I think it's always equivalent to .size ?

In [1]: arr = np.random.randn(3, 2)

In [2]: %timeit arr.size
42.8 ns ± 0.628 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [3]: %timeit np.prod(arr.shape)
6.63 µs ± 344 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

@jorisvandenbossche jorisvandenbossche added the Performance Memory or execution speed performance label Feb 15, 2021
@jbrockmendel
Copy link
Member

and I think it's always equivalent to .size

AFAIK this is correct

Could grep for this pattern elsewhere?

LGTM

@jreback jreback added this to the 1.3 milestone Feb 15, 2021
@jorisvandenbossche
Copy link
Member Author

Changed a few more (there are other cases, eg in nanops, but where we only have the shape, and not the original array, so that would require more code changes, and thus out of scope for this PR)

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jreback jreback merged commit ebc9327 into pandas-dev:master Feb 16, 2021
@jreback
Copy link
Contributor

jreback commented Feb 16, 2021

thanks @jorisvandenbossche

@jorisvandenbossche jorisvandenbossche deleted the ops-refactor-perf-use_numexpr-check branch February 17, 2021 07:09
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants