-
Notifications
You must be signed in to change notification settings - Fork 46
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
sequence() was the bottleneck in my program #451
Comments
Optimizations: * cache sequence(). See PDLPorters/pdl#451 * Use scalars when comparing 1,1-piddles * Only evaluate slices when necessary. For example, bestPos is only used when a better fit is found ($sfit < $bestfit) * Remove ->copy from temp variable, there is no re-assignment. * Group scalar math together with parens _before_ applying that result to a PDL. Possible performance side-effects: * When logging is enabled, some PDL operations happen more than once, but I bet the printf takes longer than the PDL op. * getBestFit() creates a PDL on return, so maybe a touch slower, but it drastically speeds up internals with scalar comparisons.
Notes on profiling C/XS code: https://www.perlmonks.org/?node_id=791611 |
With the above, |
Ironically, the |
With the changes linked above, on my machine it's now about twice as quick (450ms) as when I started. |
With the above-linked commit, this is now taking about 380ms here. Notes on identifying this and probably similar performance bottlenecks, using
The first two are the top-two expensive functions, the most so being the unexpected
That confirmed it was indeed coming from
This is how long after, about 20% less time:
|
With that commit, the 10m The |
For more performance issues, see the benchmark on nrdvana/perl-Math-3Space#8. The stripped-down timings:
Here, PDL::LinearAlgebra does make things quicker. |
I was surprised to find that the
sequence()
function was the bottleneck in a Particle Swarm optimization. Ultimately I cached$sequence = sequence(@foo)
instead of generating it every time it was used.Not sure if there is room to optimize
sequence
or not, but here is the nytprof output.Before caching:
After caching:
Caching fixed it for me in my own program, but FYI in case it helps others, or if it can be addressed somehow.
The text was updated successfully, but these errors were encountered: