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

add a summary table to benchmark compare output #8399

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions benchmarks/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def compare(
noise_threshold: float,
) -> None:
baseline = BenchmarkRun.load_from_file(baseline_path)

comparison = BenchmarkRun.load_from_file(comparison_path)

console = Console()
Expand All @@ -124,27 +123,57 @@ def compare(
table.add_column(comparison_header, justify="right", style="dim")
table.add_column("Change", justify="right", style="dim")

faster_count = 0
slower_count = 0
no_change_count = 0
total_baseline_time = 0
total_comparison_time = 0

for baseline_result, comparison_result in zip(baseline.queries, comparison.queries):
assert baseline_result.query == comparison_result.query

total_baseline_time += baseline_result.execution_time
total_comparison_time += comparison_result.execution_time

change = comparison_result.execution_time / baseline_result.execution_time

if (1.0 - noise_threshold) <= change <= (1.0 + noise_threshold):
change = "no change"
change_text = "no change"
no_change_count += 1
elif change < 1.0:
change = f"+{(1 / change):.2f}x faster"
change_text = f"+{(1 / change):.2f}x faster"
faster_count += 1
else:
change = f"{change:.2f}x slower"
change_text = f"{change:.2f}x slower"
slower_count += 1

table.add_row(
f"Q{baseline_result.query}",
f"{baseline_result.execution_time:.2f}ms",
f"{comparison_result.execution_time:.2f}ms",
change,
change_text,
)

console.print(table)

# Calculate averages
avg_baseline_time = total_baseline_time / len(baseline.queries)
avg_comparison_time = total_comparison_time / len(comparison.queries)

# Summary table
summary_table = Table(show_header=True, header_style="bold magenta")
summary_table.add_column("Benchmark Summary", justify="left", style="dim")
summary_table.add_column("", justify="right", style="dim")

summary_table.add_row(f"Total Time ({baseline_header})", f"{total_baseline_time:.2f}ms")
summary_table.add_row(f"Total Time ({comparison_header})", f"{total_comparison_time:.2f}ms")
summary_table.add_row(f"Average Time ({baseline_header})", f"{avg_baseline_time:.2f}ms")
summary_table.add_row(f"Average Time ({comparison_header})", f"{avg_comparison_time:.2f}ms")
summary_table.add_row("Queries Faster", str(faster_count))
summary_table.add_row("Queries Slower", str(slower_count))
summary_table.add_row("Queries with No Change", str(no_change_count))

console.print(summary_table)

def main() -> None:
parser = ArgumentParser()
Expand Down