mirror of
https://github.com/Lore09/Tesi-Magistrale.git
synced 2025-12-20 04:44:32 +00:00
updated plots
This commit is contained in:
92
plot_compared_metrics.py
Normal file
92
plot_compared_metrics.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import seaborn as sns
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import yaml
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Function to read and parse a metric file
|
||||||
|
def read_metrics(file_path, label):
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
data = yaml.safe_load(file)
|
||||||
|
runs = data['runs']
|
||||||
|
|
||||||
|
extracted_data = []
|
||||||
|
for run in runs:
|
||||||
|
if 'build' in run:
|
||||||
|
extracted_data.append({'Task': run['n_task'], 'Type': 'Build Time', 'Time': float(run['build']['components_build_time']), 'Source': label})
|
||||||
|
|
||||||
|
if 'code_gen' in run:
|
||||||
|
extracted_data.append({'Task': run['n_task'], 'Type': 'Generation Time', 'Time': float(run['code_gen']['gen_time']), 'Source': label})
|
||||||
|
|
||||||
|
if 'deploy' in run:
|
||||||
|
extracted_data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time']), 'Source': label})
|
||||||
|
|
||||||
|
if 'time_total' in run:
|
||||||
|
extracted_data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total']), 'Source': label})
|
||||||
|
|
||||||
|
return extracted_data
|
||||||
|
|
||||||
|
# Paths for the two metric files
|
||||||
|
file_path_1 = 'project/metrics.yaml' # First metrics file
|
||||||
|
file_path_2 = 'auga/metrics.yaml' # Second metrics file
|
||||||
|
|
||||||
|
# Read and combine the data
|
||||||
|
data1 = read_metrics(file_path_1, 'Parallel')
|
||||||
|
data2 = read_metrics(file_path_2, 'Sequential')
|
||||||
|
|
||||||
|
df = pd.DataFrame(data1 + data2)
|
||||||
|
|
||||||
|
# Ensure benchmark directory exists
|
||||||
|
os.makedirs('benchmark', exist_ok=True)
|
||||||
|
|
||||||
|
# Function to plot boxplot
|
||||||
|
def plot_boxplot(metric, filename):
|
||||||
|
subset = df[df['Type'] == metric]
|
||||||
|
plt.figure(figsize=(10, 6))
|
||||||
|
sns.boxplot(x='Task', y='Time', hue='Source', data=subset, showfliers=False)
|
||||||
|
|
||||||
|
plt.ylabel('Time (seconds)')
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.7)
|
||||||
|
plt.legend(title='Source')
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.savefig(f'benchmark/{filename}')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
# Function to plot line plot with confidence intervals
|
||||||
|
def plot_lineplot(metric, filename):
|
||||||
|
subset = df[df['Type'] == metric]
|
||||||
|
plt.figure(figsize=(10, 6))
|
||||||
|
sns.lineplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95), linewidth=2, marker='o')
|
||||||
|
|
||||||
|
plt.xlabel('Number of Tasks')
|
||||||
|
plt.ylabel('Time (seconds)')
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.7)
|
||||||
|
plt.legend(title='Source')
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.savefig(f'benchmark/{filename}')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
# Function to plot bar plot with confidence intervals
|
||||||
|
def plot_barplot(metric, filename):
|
||||||
|
subset = df[df['Type'] == metric]
|
||||||
|
plt.figure(figsize=(10, 6))
|
||||||
|
sns.barplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95))
|
||||||
|
|
||||||
|
plt.ylabel('Time (seconds)')
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.7)
|
||||||
|
plt.legend(title='Source')
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.savefig(f'benchmark/{filename}')
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
# Generate plots for each metric
|
||||||
|
metrics = ['Build Time', 'Generation Time', 'Deployment Time', 'Total Time']
|
||||||
|
filenames = ['build_time', 'gen_time', 'deploy_time', 'total_time']
|
||||||
|
|
||||||
|
for metric, filename in zip(metrics, filenames):
|
||||||
|
#plot_boxplot(metric, f'{filename}_boxplot.png')
|
||||||
|
#plot_lineplot(metric, f'{filename}_lineplot.png')
|
||||||
|
plot_barplot(metric, f'{filename}_paired_barplot.png')
|
||||||
|
|
||||||
|
print('Comparison plots saved successfully in "benchmark" directory!')
|
||||||
@@ -12,7 +12,7 @@ def read_metrics(file_path):
|
|||||||
return data['runs']
|
return data['runs']
|
||||||
|
|
||||||
# Read metrics from the file
|
# Read metrics from the file
|
||||||
file_path = 'project/metrics.yaml' # Replace with your file path
|
file_path = 'res/metrics-parallel.yaml' # Replace with your file path
|
||||||
runs = read_metrics(file_path)
|
runs = read_metrics(file_path)
|
||||||
|
|
||||||
# Flatten data into a list of dictionaries
|
# Flatten data into a list of dictionaries
|
||||||
@@ -27,6 +27,9 @@ for run in runs:
|
|||||||
if 'deploy' in run:
|
if 'deploy' in run:
|
||||||
data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time'])})
|
data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time'])})
|
||||||
|
|
||||||
|
if 'time_total' in run:
|
||||||
|
data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total'])})
|
||||||
|
|
||||||
# Convert to DataFrame
|
# Convert to DataFrame
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
|
|
||||||
@@ -91,16 +94,20 @@ def plot_barplot(metric, filename, color):
|
|||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
# Plot each metric separately
|
# Plot each metric separately
|
||||||
plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue')
|
#plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue')
|
||||||
plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue')
|
#plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue')
|
||||||
plot_barplot('Build Time', 'build_time_barplot.png', 'skyblue')
|
plot_barplot('Build Time', 'build_time_barplot.png', 'skyblue')
|
||||||
|
|
||||||
plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen')
|
#plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen')
|
||||||
plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen')
|
#plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen')
|
||||||
plot_barplot('Generation Time', 'gen_time_barplot.png', 'lightgreen')
|
plot_barplot('Generation Time', 'gen_time_barplot.png', 'lightgreen')
|
||||||
|
|
||||||
plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon')
|
#plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon')
|
||||||
plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon')
|
#plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon')
|
||||||
plot_barplot('Deployment Time', 'deploy_time_barplot.png', 'salmon')
|
plot_barplot('Deployment Time', 'deploy_time_barplot.png', 'salmon')
|
||||||
|
|
||||||
|
#plot_boxplot('Total Time', 'total_time_boxplot.png', 'purple')
|
||||||
|
#plot_lineplot('Total Time', 'total_time_lineplot.png', 'purple')
|
||||||
|
plot_barplot('Total Time', 'total_time_barplot.png', 'orange')
|
||||||
|
|
||||||
print('Plots saved successfully in "benchmark" directory!')
|
print('Plots saved successfully in "benchmark" directory!')
|
||||||
|
|||||||
Reference in New Issue
Block a user