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

RFC: benchmark decorator #482

Closed
philpep opened this issue Oct 28, 2016 · 4 comments
Closed

RFC: benchmark decorator #482

philpep opened this issue Oct 28, 2016 · 4 comments
Labels
enhancement Triaged as an enhancement request

Comments

@philpep
Copy link
Contributor

philpep commented Oct 28, 2016

I think it could be more pythonic to handle benchmark attributes (params, setup etc) through a single decorator, this way it's more explicit to understand that arguments are injected in the function.

eg:

@asv.benchmark(params={'foo': ['bar', 'baz']}, type='time')
def mybench(self, foo):
    [...]

But I guess we don't have asv installed in the virtualenv used during benchmark and injecting the decorator while loading the module isn't explicit too.

@pv pv added the enhancement Triaged as an enhancement request label Nov 6, 2016
@pv
Copy link
Collaborator

pv commented Nov 6, 2016

I agree that a decorator is a nicer way to do it, and I think larger benchmark suites likely end up writing such a decorator themselves.

I think a problem (or inelegancy) here is in exposing the asvtools module that contains the decorator. The decorator itself is also 6 lines of code, so if it's the only thing that would be there one can ask is it worth the trouble. Such asvtools module was thought of at some point earlier: #182

@shoyer
Copy link

shoyer commented Jan 24, 2018

Maybe a recipe for such a decorator could simply be added to the ASV docs? I'd be happy to copy it into my project, but it would be nice not to have to think too hard about the design :).

I suppose the canonical implementation is something like:

def parameterized(names, params):
    def decorator(func):
        func.param_names = names
        func.params = params
        return func
    return decorator

(only 5 lines, not 6!)

@soupault
Copy link

Looking at http://asv.readthedocs.io/en/latest/writing_benchmarks.html, I've just come across the same idea. Sticking to method names is not quite Pythonic and, potentially, error-prone. 👍

@HaoZeke
Copy link
Member

HaoZeke commented Aug 20, 2023

Closing as completed in airspeed-velocity/asv_runner#18 (and discussed a bit more in #1266).

@HaoZeke HaoZeke closed this as completed Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Triaged as an enhancement request
Projects
None yet
Development

No branches or pull requests

5 participants