mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
benchs
This commit is contained in:
@@ -4,14 +4,14 @@ from pathlib import Path
|
|||||||
|
|
||||||
import matplotlib
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
from ..benchmarks.core.models import BenchmarkGroupResult
|
from ..benchmarks.core.models import BenchmarkGroupResult
|
||||||
|
|
||||||
|
|
||||||
class DiagramGenerator:
|
class DiagramGenerator:
|
||||||
def __init__(self, output_dir: Path | str) -> None:
|
def __init__(self, output_dir: Path | str) -> None:
|
||||||
self.output_dir = output_dir
|
self.output_dir: Path = Path(output_dir) if isinstance(output_dir, str) else output_dir
|
||||||
|
|
||||||
matplotlib.use('Agg')
|
matplotlib.use('Agg')
|
||||||
plt.style.use('seaborn-v0_8-whitegrid')
|
plt.style.use('seaborn-v0_8-whitegrid')
|
||||||
|
|
||||||
@@ -19,33 +19,46 @@ class DiagramGenerator:
|
|||||||
results = benchmark_group.benchmark_results
|
results = benchmark_group.benchmark_results
|
||||||
sorted_results = sorted(results, key=lambda br: br.avg_time)
|
sorted_results = sorted(results, key=lambda br: br.avg_time)
|
||||||
|
|
||||||
descriptions = [br.description for br in sorted_results]
|
descriptions: list[str] = [br.description for br in sorted_results]
|
||||||
avg_times = [br.avg_time for br in sorted_results]
|
avg_times: list[float] = [br.avg_time for br in sorted_results]
|
||||||
median_times = [br.median_time for br in sorted_results]
|
median_times: list[float] = [br.median_time for br in sorted_results]
|
||||||
std_devs = [br.std_dev for br in sorted_results]
|
std_devs: list[float] = [br.std_dev for br in sorted_results]
|
||||||
|
|
||||||
max_value = max(max(avg_times), max(median_times), max(std_devs))
|
max_value = max(
|
||||||
y_limit = max_value / 0.85
|
max(avg_times) if avg_times else 0,
|
||||||
|
max(median_times) if median_times else 0,
|
||||||
|
max(std_devs) if std_devs else 0
|
||||||
|
)
|
||||||
|
y_limit = max_value / 0.85 if max_value > 0 else 1.0
|
||||||
|
|
||||||
x = np.arange(len(descriptions))
|
items_count = len(descriptions)
|
||||||
width = 0.25
|
x_positions: list[int] = list(range(items_count))
|
||||||
|
|
||||||
|
bar_width = 0.25
|
||||||
|
|
||||||
|
x_std_dev = [x - bar_width for x in x_positions]
|
||||||
|
x_avg = [x for x in x_positions]
|
||||||
|
x_median = [x + bar_width for x in x_positions]
|
||||||
|
|
||||||
fig, ax = plt.subplots(figsize=(16, 8))
|
fig, ax = plt.subplots(figsize=(16, 8))
|
||||||
fig.patch.set_facecolor('white')
|
fig.patch.set_facecolor('white')
|
||||||
|
|
||||||
bars1 = ax.bar(x - width, std_devs, width, label='Std Deviation',
|
bars_std = ax.bar(x_std_dev, std_devs, bar_width, label='Std Deviation',
|
||||||
color='#2ecc71', alpha=0.9, edgecolor='#27ae60', linewidth=1.5)
|
color='#2ecc71', alpha=0.9, edgecolor='#27ae60', linewidth=1.5)
|
||||||
bars2 = ax.bar(x, avg_times, width, label='Average Time',
|
bars_avg = ax.bar(x_avg, avg_times, bar_width, label='Average Time',
|
||||||
color='#3498db', alpha=0.9, edgecolor='#2980b9', linewidth=1.5)
|
color='#3498db', alpha=0.9, edgecolor='#2980b9', linewidth=1.5)
|
||||||
bars3 = ax.bar(x + width, median_times, width, label='Median Time',
|
bars_median = ax.bar(x_median, median_times, bar_width, label='Median Time',
|
||||||
color='#e74c3c', alpha=0.9, edgecolor='#c0392b', linewidth=1.5)
|
color='#e74c3c', alpha=0.9, edgecolor='#c0392b', linewidth=1.5)
|
||||||
|
|
||||||
for bars in [bars1, bars2, bars3]:
|
for bar_group in [bars_std, bars_avg, bars_median]:
|
||||||
for bar in bars:
|
for bar in bar_group:
|
||||||
height = bar.get_height()
|
height = bar.get_height()
|
||||||
ax.text(bar.get_x() + bar.get_width() / 2., height,
|
ax.text(
|
||||||
f'{height:.3f}',
|
bar.get_x() + bar.get_width() / 2.,
|
||||||
ha='center', va='bottom', fontsize=9, fontweight='bold')
|
height,
|
||||||
|
f'{height:.3f}',
|
||||||
|
ha='center', va='bottom', fontsize=9, fontweight='bold'
|
||||||
|
)
|
||||||
|
|
||||||
ax.set_ylabel('Time (ms)', fontsize=14, fontweight='bold', labelpad=10)
|
ax.set_ylabel('Time (ms)', fontsize=14, fontweight='bold', labelpad=10)
|
||||||
|
|
||||||
@@ -57,14 +70,18 @@ class DiagramGenerator:
|
|||||||
ax.text(0.5, 1.03, metadata_text, transform=ax.transAxes,
|
ax.text(0.5, 1.03, metadata_text, transform=ax.transAxes,
|
||||||
fontsize=12, ha='center', color='#7f8c8d', style='italic')
|
fontsize=12, ha='center', color='#7f8c8d', style='italic')
|
||||||
|
|
||||||
ax.set_xticks(x)
|
ax.set_xticks(x_positions)
|
||||||
ax.set_xticklabels([])
|
ax.set_xticklabels([])
|
||||||
|
|
||||||
for i, (pos, desc) in enumerate(zip(x, descriptions)):
|
for i, (pos, desc) in enumerate(zip(x_positions, descriptions)):
|
||||||
bar_x = pos - width - width / 2
|
text_x_pos = pos - bar_width - (bar_width / 2)
|
||||||
ax.text(bar_x, y_limit * 0.02, desc,
|
ax.text(
|
||||||
rotation=90, va='bottom', ha='right', fontsize=10,
|
text_x_pos,
|
||||||
color='#2c3e50')
|
y_limit * 0.02,
|
||||||
|
desc,
|
||||||
|
rotation=90, va='bottom', ha='right', fontsize=10,
|
||||||
|
color='#2c3e50'
|
||||||
|
)
|
||||||
|
|
||||||
ax.set_ylim(0, y_limit)
|
ax.set_ylim(0, y_limit)
|
||||||
|
|
||||||
@@ -84,6 +101,9 @@ class DiagramGenerator:
|
|||||||
|
|
||||||
filename = f"{benchmark_group.type_}_comparison.png"
|
filename = f"{benchmark_group.type_}_comparison.png"
|
||||||
output_path = self.output_dir / filename
|
output_path = self.output_dir / filename
|
||||||
|
|
||||||
|
self.output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
plt.savefig(output_path, dpi=200, bbox_inches='tight', facecolor='white')
|
plt.savefig(output_path, dpi=200, bbox_inches='tight', facecolor='white')
|
||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user