Skip to content

Commit

Permalink
Include axis range information
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Mar 15, 2024
1 parent 25d856a commit 1490250
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
27 changes: 22 additions & 5 deletions tools/benchcomp/benchcomp/visualizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,15 @@ def _get_template():
quadrant-2 2
quadrant-3 3
quadrant-4 4
{%- for bench_name, bench_variants in d["scaled_metrics"][metric].items () %}
{%- for bench_name, bench_variants in d["scaled_metrics"][metric]["benchmarks"].items () %}
{% set v0 = bench_variants[d["scaled_variants"][metric][0]] -%}
{% set v1 = bench_variants[d["scaled_variants"][metric][1]] -%}
"{{ bench_name }}": [{{ v0|round(3) }}, {{ v1|round(3) }}]
{%- endfor %}
```
Scatterplot axis ranges are
{{ d["scaled_metrics"][metric]["min_value"] }} (bottom/left) to
{{ d["scaled_metrics"][metric]["max_value"] }} (top/right).
{% endif -%}
| Benchmark | {% for variant in d["variants"][metric] %} {{ variant }} |{% endfor %}
Expand Down Expand Up @@ -293,13 +296,17 @@ def _compute_scaled_metric(data_for_metric, log_scaling):
min_value = variant_result
if max_value is None or variant_result > max_value:
max_value = variant_result
ret = {bench: {} for bench in data_for_metric.keys()}
ret = {
"benchmarks": {bench: {} for bench in data_for_metric.keys()},
"min_value": "log({})".format(min_value) if log_scaling else min_value,
"max_value": "log({})".format(max_value) if log_scaling else max_value,
}
# 1.0 is not a permissible value for mermaid, so make sure all scaled
# results stay below that by use 0.99 as hard-coded value or
# artificially increasing the range by 10 per cent
if min_value is None or min_value == max_value:
for bench, bench_result in data_for_metric.items():
ret[bench] = {variant: 0.99 for variant in bench_result.keys()}
ret["benchmarks"][bench] = {variant: 0.99 for variant in bench_result.keys()}
else:
if log_scaling:
min_value = math.log(min_value, 10)
Expand All @@ -312,7 +319,7 @@ def _compute_scaled_metric(data_for_metric, log_scaling):
abs_value = math.log(variant_result, 10)
else:
abs_value = variant_result
ret[bench][variant] = (abs_value - min_value) / value_range
ret["benchmarks"][bench][variant] = (abs_value - min_value) / value_range
return ret


Expand Down Expand Up @@ -366,6 +373,16 @@ def _get_variants(metrics):
return ret


@staticmethod
def _get_scaled_variants(metrics):
ret = {}
for metric, entries in metrics.items():
for bench, variants in entries["benchmarks"].items():
ret[metric] = list(variants.keys())
break
return ret


def __call__(self, results):
(metrics, scaled) = self._organize_results_into_metrics(
results, self.scatterplot == Plot.LOG)
Expand All @@ -375,7 +392,7 @@ def __call__(self, results):
"metrics": metrics,
"variants": self._get_variants(metrics),
"scaled_metrics": scaled,
"scaled_variants": self._get_variants(scaled),
"scaled_variants": self._get_scaled_variants(scaled),
}

env = jinja2.Environment(
Expand Down
5 changes: 5 additions & 0 deletions tools/benchcomp/test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def test_markdown_results_table(self):
run_bc()

self.assertEqual(run_bc.proc.returncode, 0, msg=run_bc.stderr)
self.maxDiff = None
self.assertEqual(
run_bc.stdout, textwrap.dedent("""
## runtime
Expand All @@ -475,6 +476,10 @@ def test_markdown_results_table(self):
"bench_1": [0.0, 0.909]
"bench_2": [0.909, 0.0]
```
Scatterplot axis ranges are
5 (bottom/left) to
10 (top/right).
| Benchmark | variant_1 | variant_2 | ratio |
| --- | --- | --- | --- |
Expand Down

0 comments on commit 1490250

Please sign in to comment.