From b335cc6d88e9277acd1bd6f7263d36d93fb64690 Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Fri, 8 Apr 2016 18:01:34 +0200 Subject: [PATCH] Implement "pretty_name" attribute on benchmark func 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 #424 --- asv/benchmark.py | 1 + asv/www/graphdisplay.js | 3 ++- docs/source/writing_benchmarks.rst | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/asv/benchmark.py b/asv/benchmark.py index 8ef427488..5a2adfb10 100644 --- a/asv/benchmark.py +++ b/asv/benchmark.py @@ -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)) diff --git a/asv/www/graphdisplay.js b/asv/www/graphdisplay.js index 91b37fc18..81dcdc993 100644 --- a/asv/www/graphdisplay.js +++ b/asv/www/graphdisplay.js @@ -225,7 +225,8 @@ $(document).ready(function() { }); } - var top = $('
  • ' + parts[parts.length - 1] + '
  • '); + var name = bm.pretty_name || bm.name || parts[parts.length - 1]; + var top = $('
  • ' + name + '
  • '); stack[stack.length - 1].append(top); top.tooltip({ diff --git a/docs/source/writing_benchmarks.rst b/docs/source/writing_benchmarks.rst index 44f613f0b..0128e9197 100644 --- a/docs/source/writing_benchmarks.rst +++ b/docs/source/writing_benchmarks.rst @@ -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 ------------------------