-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Large overhead in some random functions #15460
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
Comments
Agreed, hopefully the slowness is enough to motivate people not to use it ;) |
Is a similar speedup possible for
We're only talking a couple of microseconds, but it's worth it if it's an easy win. |
I consider it a speed bug, since the added overhead is a small factor larger than a typical (fairly simple) python function call (and almost a factor of 10 of what it should be). |
I will try to speed it up ;) WIP |
slow calls to np.dtype.name replaced with np.dtype, mtrand.pyx and _generator.pyx updated, test test_warns_byteorder updated before: %timeit rs.random(): 520 ns ± 33.1 ns per loop %timeit rg.random(): 6.36 µs ± 222 ns per loop after: %timeit rs.random(): 453 ns ± 6.95 ns per loop %timeit rg.random(): 594 ns ± 9.66 ns per loop
slow calls to np.dtype.name replaced with np.dtype, mtrand.pyx and _generator.pyx updated, test test_warns_byteorder updated before: %timeit rs.random(): 520 ns ± 33.1 ns per loop %timeit rg.random(): 6.36 µs ± 222 ns per loop after: %timeit rs.random(): 453 ns ± 6.95 ns per loop %timeit rg.random(): 594 ns ± 9.66 ns per loop
This issue is extracted from gitter (by @andyfaff – I saw it only randomly, so creating this before we forget).
Some random generator functions such as
random()
have a huge overhead compared to their legacyRandomState
versions:The reason for this is the support of the
dtype=
keyword argument. A secondary reason (and maybe second speed issue) is thatnp.dtype.name
is a very slow operations (it could plausibly be cached).However, the solution here will be to simply avoid the whole
np.dtype(dtype).name
construct as much as possible and maybe adding a fastpath for the case whendtype
is not used.np.dtype(dtype).type is np.float64
may be a solution, ordtype is np.float64 or np.dtype(dtype) is np.float64
to speed up the default branch.Checking that we have benchmarks – or adding simple small array ones in a first commit – for this would be good when this is fixed.
The text was updated successfully, but these errors were encountered: