Skip to content

Commit

Permalink
Implement "pretty_name" attribute on benchmark func
Browse files Browse the repository at this point in the history
This optional parameter is printed in web UI instead of function name
allowing to use all characters set that would be avoided for a python
function name.

Closes airspeed-velocity#424
  • Loading branch information
philpep committed Jun 3, 2016
1 parent 88dee44 commit b335cc6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def __init__(self, name, func, attr_sources):
name = name.split('.', 1)[1]
self.name = name
self.func = func
self.pretty_name = getattr(func, "pretty_name", name)
self._attr_sources = attr_sources
self._setups = list(_get_all_attrs(attr_sources, 'setup', True))[::-1]
self._teardowns = list(_get_all_attrs(attr_sources, 'teardown', True))
Expand Down
3 changes: 2 additions & 1 deletion asv/www/graphdisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ $(document).ready(function() {
});
}

var top = $('<li><a href="#' + bm_name + '">' + parts[parts.length - 1] + '</li>');
var name = bm.pretty_name || bm.name || parts[parts.length - 1];
var top = $('<li><a href="#' + bm_name + '">' + name + '</li>');
stack[stack.length - 1].append(top);

top.tooltip({
Expand Down
3 changes: 3 additions & 0 deletions docs/source/writing_benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ The following attributes are applicable to all benchmark types:
- ``timeout``: The amount of time, in seconds, to give the benchmark
to run before forcibly killing it. Defaults to 60 seconds.

- ``pretty_name``: If given, used to display the benchmark name instead of the
benchmark function name.

Parameterized benchmarks
------------------------

Expand Down

0 comments on commit b335cc6

Please sign in to comment.