-
Notifications
You must be signed in to change notification settings - Fork 88
Add --extra-metadata support to compare_to command #221
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,13 @@ def cpu_affinity(cmd): | |
| cmd.add_argument("--table-format", type=str, default="rest", | ||
| choices=["rest", "md"], | ||
| help="Format of table rendering") | ||
| cmd.add_argument( | ||
| "--extra-metadata", | ||
| type=str, | ||
| help="Comma-separated metadata keys to include in comparison output." | ||
| ) | ||
|
|
||
| >>>>>>> 868272e (Temp: save working changes before branch switch) | ||
|
||
| input_filenames(cmd) | ||
|
|
||
| # stats | ||
|
|
@@ -389,6 +396,9 @@ def cmd_compare_to(args): | |
| from pyperf._compare import compare_suites, CompareError | ||
|
|
||
| data = load_benchmarks(args) | ||
| if getattr(args, "extra_metadata", None): | ||
| display_title("Benchmark") | ||
| print() | ||
| if data.get_nsuite() < 2: | ||
| print("ERROR: need at least two benchmark files") | ||
| sys.exit(1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,7 @@ def get_tags_for_result(result): | |||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class CompareResult: | ||||||||||||||||||
| def __init__(self, ref, changed, min_speed=None): | ||||||||||||||||||
| def __init__(self, ref, changed, min_speed=None, extra_metadata=None): | ||||||||||||||||||
| # CompareData object | ||||||||||||||||||
| self.ref = ref | ||||||||||||||||||
| # CompareData object | ||||||||||||||||||
|
|
@@ -63,6 +63,7 @@ def __init__(self, ref, changed, min_speed=None): | |||||||||||||||||
| self._significant = None | ||||||||||||||||||
| self._t_score = None | ||||||||||||||||||
| self._norm_mean = None | ||||||||||||||||||
| self.extra_metadata = extra_metadata or [] | ||||||||||||||||||
|
|
||||||||||||||||||
| def __repr__(self): | ||||||||||||||||||
| return '<CompareResult ref=%r changed=%r>' % (self.ref, self.changed) | ||||||||||||||||||
|
|
@@ -110,21 +111,36 @@ def oneliner(self, verbose=True, show_name=True, check_significant=True): | |||||||||||||||||
|
|
||||||||||||||||||
| ref_text = format_result_value(self.ref.benchmark) | ||||||||||||||||||
| chg_text = format_result_value(self.changed.benchmark) | ||||||||||||||||||
|
|
||||||||||||||||||
| if verbose: | ||||||||||||||||||
| if show_name: | ||||||||||||||||||
| ref_text = "[%s] %s" % (self.ref.name, ref_text) | ||||||||||||||||||
| chg_text = "[%s] %s" % (self.changed.name, chg_text) | ||||||||||||||||||
| if (self.ref.benchmark.get_nvalue() > 1 | ||||||||||||||||||
| or self.changed.benchmark.get_nvalue() > 1): | ||||||||||||||||||
|
|
||||||||||||||||||
| if (self.ref.benchmark.get_nvalue() > 1 or self.changed.benchmark.get_nvalue() > 1): | ||||||||||||||||||
|
||||||||||||||||||
| text = "Mean +- std dev: %s -> %s" % (ref_text, chg_text) | ||||||||||||||||||
| else: | ||||||||||||||||||
| text = "%s -> %s" % (ref_text, chg_text) | ||||||||||||||||||
| else: | ||||||||||||||||||
| text = "%s -> %s" % (ref_text, chg_text) | ||||||||||||||||||
|
|
||||||||||||||||||
| # normalized mean | ||||||||||||||||||
| text = "%s: %s" % (text, format_normalized_mean(self.norm_mean)) | ||||||||||||||||||
| return text | ||||||||||||||||||
|
|
||||||||||||||||||
| # EXTRA METADATA SUPPORT | ||||||||||||||||||
| if self.extra_metadata: | ||||||||||||||||||
|
||||||||||||||||||
| # EXTRA METADATA SUPPORT | |
| if self.extra_metadata: | |
| # Extra metadata support | |
| if self.extra_metadata: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| result = CompareResult( | |
| ref, | |
| changed, | |
| min_speed, | |
| extra_metadata=self.extra_metadata | |
| ) | |
| result = CompareResult(ref, changed, min_speed, | |
| extra_metadata=self.extra_metadata) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| import pyperf | ||
|
|
||
|
|
||
| def create_temp_benchmark(tmpdir, data): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to reuse one of the existing benchmark file in pyperf/tests: |
||
| import uuid | ||
| """ | ||
| Create a valid pyperf JSON benchmark file. | ||
| pyperf requires the structure: | ||
| { | ||
| "version": "1.0", | ||
| "benchmarks": [ | ||
| { | ||
| "metadata": {...}, | ||
| "runs": [...] | ||
| } | ||
| ] | ||
| } | ||
| """ | ||
|
|
||
| # pyperf requires a benchmark name + unit | ||
| metadata = { | ||
| "name": "test_bench", | ||
| "unit": "second" | ||
| } | ||
| metadata.update(data.get("metadata", {})) | ||
|
|
||
| benchmark = { | ||
| "metadata": metadata, | ||
| "runs": data.get("runs", []) | ||
| } | ||
|
|
||
| suite = { | ||
| "version": "1.0", | ||
| "benchmarks": [benchmark] | ||
| } | ||
|
|
||
| path = os.path.join(tmpdir, f"bench_{uuid.uuid4().hex}.json") | ||
| with open(path, "w", encoding="utf-8") as f: | ||
| json.dump(suite, f) | ||
|
|
||
| return path | ||
|
|
||
|
|
||
| def run_command(cmd): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pyperf/tests/test_perf_cli.py already has a run_command() method. |
||
| proc = subprocess.Popen( | ||
| [sys.executable, "-m", "pyperf"] + cmd, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| text=True, | ||
| ) | ||
| stdout, stderr = proc.communicate() | ||
| return stdout, stderr | ||
|
|
||
|
|
||
| def test_compare_to_with_extra_metadata(tmpdir): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test to pyperf/tests/test_perf_cli.py instead? |
||
| # 1. Create benchmark files with metadata | ||
| bench1 = create_temp_benchmark(tmpdir, { | ||
| "metadata": {"os": "linux", "cpu": "amd"}, | ||
| "runs": [{"values": [1.0]}] | ||
| }) | ||
|
|
||
| bench2 = create_temp_benchmark(tmpdir, { | ||
| "metadata": {"os": "linux", "cpu": "intel"}, | ||
| "runs": [{"values": [1.0]}] | ||
| }) | ||
|
|
||
| # 2. Run compare_to | ||
| cmd = [ | ||
| "compare_to", | ||
| "--extra-metadata=os,cpu", | ||
| bench1, | ||
| bench2, | ||
| ] | ||
|
|
||
| stdout, stderr = run_command(cmd) | ||
|
|
||
| # 3. Assertions | ||
| assert stderr == "" | ||
| assert "os" in stdout | ||
| assert "cpu" in stdout | ||
| assert "linux" in stdout | ||
| assert "amd" in stdout | ||
| assert "intel" in stdout | ||
| assert "Benchmark" in stdout | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.