-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
BENCH: Split bench_function_base.Sort into Sort and SortWorst. #11889
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
Conversation
SortWorst houses the worst-case setup code and the time_sort_worst method. Everything else remains in Sort. Done in response to issue numpy#11875
I note that the same data is passed in every time. Is it possible to split that out into class attributes and just make copies in the setup functions? @pv Thoughts. |
Wow, looks like asv reloads the whole module for every test run. That is just horribly wrong. Anyway, I can get a 3x speedup of the sort benchmark with the following.
How does that compare? I expect with your split in addition it will be even faster, |
@charris I got a 7.25x speedup on just the setup calls, didn't time the entire benchmark. I suspect that your strategy is likely marginally slower than mine in this case, since there's still overhead on copying Sort.worst for each method. I don't think combining them would yield a significant boost over mine, since the other test arrays are fairly small. Could be wrong though. Maybe the most coherent strategy given how asv does things would be to enforce one test method per class. So the resulting Sort suite would have the classes: or some other naming convention. This would prevent redundant setup work. Also relevant is what's at stake. I'm not too familiar with how these benchmarks are used, maybe it's not worth the work. |
I checked with your PR, and it gives another 2x improvement in the I'm not sure how far it is worth pursuing, but it is worth understanding how to improve the performance. |
If you want to go fancy, I imagine you can write a metaclass in 10 lines that does name-based setup assignment, |
@charris a 2x speedup in the setup? or in the entire benchmark? That's interesting. I had assumed asv was just running each test method once, but if its doing repeated calls to setup() and then time_sort_worst(), your speedup on SortWorst would make sense. I tried digging into the asv codebase but didn't get very far. |
Docs for how the setup/etc works is here: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#setup-and-teardown-functions |
|
More like six times. You can do a print in the setup function to see that. |
@pv yes I read through that. What I couldn't figure out was how many times a given test method is being called by asv. If setup precedes time_sort_worst on every call, and time_sort_worst is called 100 times, then cacheing the setup data makes sense. If time_sort_worst is only called once, then it doesn't, but it does make sense to split the slower data generation out from the other test methods. |
@charris ok, that clears that up then, thanks. How you do propose we move forward? I can rewrite my PR to integrate your strategy. |
@charris Actually, looking back at my notes, your strategy can probably be used to speed up the other slow setups as well. I'll look into that. |
I think your improvement is probably adequate as we aren't really pressed for performance yet. But I'd like to fool around with this a bit more. One strange thing that is happening with latest asv 0.3 is that an error message from the totally unrelated |
@charris yeah I was getting that too. I seem to remember doing something that mitigated it, but it was a couple weeks ago and I didn't make note of it. I'll look at the code and let you know if I remember anything. Thanks for the discussion, I definitely understand this better now. |
Thanks @michaelsaah . I'll leave further optimizations to you if you want to pursue them. I fixed the asv messages in |
SortWorst houses the worst-case setup code and the time_sort_worst method.
Everything else remains in Sort.
Done in response to issue #11875