@@ -56,66 +56,26 @@ def calculate_cumulative_speedup(df):
5656
5757 return cumulative_speedups
5858
59- def plot_cumulative_speedup (df , cumulative_speedups , output_folder , test_name ):
60- sns .set_style ("dark" )
61- sns .set_style (rc = {'axes.facecolor' : '#0d1117' })
62- plt .figure (figsize = (10 , 6 ))
63- ax = plt .gca ()
64-
65- sns .set_theme (style = "whitegrid" , rc = {"axes.edgecolor" : "#0d1117" , "xtick.color" : "#0d1117" , "ytick.color" : "#0d1117" })
66- plt .gcf ().set_facecolor ("#0d1117" )
67- ax = plt .gca ()
68-
69- sorted_df = df .sort_values (by = "resultSpeed" , ascending = False )
70-
71- library_colors = {}
72- for _ , row in sorted_df .iterrows ():
73- library_colors [(row ['libraryName' ], row ['resultType' ])] = row ['color' ]
74-
75- libraries = sorted_df ["libraryName" ].unique ()
76-
77- cumulative_speedup_read = cumulative_speedups .get ("Read" , [0 ] * len (libraries ))
78- cumulative_speedup_write = cumulative_speedups .get ("Write" , [0 ] * len (libraries ))
79-
80- num_libraries = len (libraries )
81- max_libraries = max (2 , num_libraries )
82- width = 0.8 / max_libraries
83-
84- for i , library in enumerate (libraries ):
85- read_speedup = cumulative_speedup_read [i ] if i < len (cumulative_speedup_read ) else 0
86- write_speedup = cumulative_speedup_write [i ] if i < len (cumulative_speedup_write ) else 0
87-
88- read_color = library_colors .get ((library , 'Read' ), 'gray' )
89- write_color = library_colors .get ((library , 'Write' ), 'gray' )
90-
91- font_size = max (8 , width * 30 )
92- if read_speedup != 0 :
93- read_bar = ax .bar (i - width / 2 , read_speedup , label = f"{ library } Read" , color = read_color , width = width )
94- ax .text (i - width / 2 , read_speedup - read_speedup * 0.05 ,
95- f"{ read_speedup :.2f} %" , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
96-
97- if write_speedup != 0 :
98- write_bar = ax .bar (i + width / 2 , write_speedup , label = f"{ library } Write" , color = write_color , width = width )
99- ax .text (i + width / 2 , write_speedup - write_speedup * 0.05 ,
100- f"{ write_speedup :.2f} %" , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
101-
102- ax .set_xticks (range (len (libraries )))
103- ax .set_xticklabels (libraries )
104- ax .set_title (f'{ test_name } Cumulative Speedup (Relative to Slowest Library)' , color = 'white' )
105- ax .set_xlabel ('Library Name' , color = 'white' )
106- ax .set_ylabel ('Cumulative Speedup (%)' , color = 'white' )
107-
108- handles , labels = ax .get_legend_handles_labels ()
109- for text in ax .get_xticklabels () + ax .get_yticklabels ():
110- text .set_color ('lightgray' )
111-
112- ax .legend (title = 'Library and Result Type' , loc = 'best' )
113-
114- output_file_path_speedup = os .path .join (output_folder , f'{ test_name } _Cumulative_Speedup.png' )
115- plt .savefig (output_file_path_speedup )
116- plt .close ()
117-
118- def plot_raw_comparisons (df , raw_speeds , output_folder , test_name ):
59+ def plot_speed_results (
60+ df ,
61+ speed_data ,
62+ output_folder ,
63+ test_name ,
64+ is_cumulative = False ,
65+ y_label = "Result Speed (MB/s)" ,
66+ label_metric = "MB/s"
67+ ):
68+ """
69+ Plots either cumulative speedups or raw speed comparisons for libraries.
70+
71+ Args:
72+ df (pd.DataFrame): The DataFrame containing library performance data.
73+ speed_data (dict): The speed data, with keys "Read" and "Write".
74+ output_folder (str): Path to the folder where the plot will be saved.
75+ test_name (str): Name of the test for labeling the output.
76+ is_cumulative (bool): If True, plots cumulative speedups; otherwise, raw speeds.
77+ y_label (str): Label for the y-axis.
78+ """
11979 sns .set_style ("dark" )
12080 sns .set_style (rc = {'axes.facecolor' : '#0d1117' })
12181 plt .figure (figsize = (10 , 6 ))
@@ -125,54 +85,71 @@ def plot_raw_comparisons(df, raw_speeds, output_folder, test_name):
12585 plt .gcf ().set_facecolor ("#0d1117" )
12686 ax = plt .gca ()
12787
128- sorted_df = df .sort_values (by = "resultSpeed" , ascending = False )
88+ has_read_results = "Read" in df ["resultType" ].unique ()
89+ has_write_results = "Write" in df ["resultType" ].unique ()
90+
91+ if has_read_results :
92+ sort_df = df [df ["resultType" ] == "Read" ].sort_values (by = "resultSpeed" , ascending = False )
93+ elif has_write_results :
94+ sort_df = df [df ["resultType" ] == "Write" ].sort_values (by = "resultSpeed" , ascending = False )
95+ else :
96+ print ("No read or write results found in the DataFrame." )
97+ return
12998
130- library_colors = {}
131- for _ , row in sorted_df .iterrows ():
132- library_colors [(row ['libraryName' ], row ['resultType' ])] = row ['color' ]
99+ sorted_libraries = sort_df ["libraryName" ].tolist ()
133100
134- libraries = sorted_df ["libraryName" ].unique ()
101+ library_colors = {
102+ (row ['libraryName' ], row ['resultType' ]): row ['color' ]
103+ for _ , row in df .iterrows ()
104+ }
135105
136- cumulative_speedup_read = raw_speeds .get ("Read" , [0 ] * len (libraries ))
137- cumulative_speedup_write = raw_speeds .get ("Write" , [0 ] * len (libraries ))
106+ speed_read = speed_data .get ("Read" , [0 ] * len (sorted_libraries ))
107+ speed_write = speed_data .get ("Write" , [0 ] * len (sorted_libraries ))
138108
139- num_libraries = len (libraries )
109+ num_libraries = len (sorted_libraries )
140110 max_libraries = max (2 , num_libraries )
141111 width = 0.8 / max_libraries
142112
143- for i , library in enumerate (libraries ):
144- read_speedup = cumulative_speedup_read [i ] if i < len (cumulative_speedup_read ) else 0
145- write_speedup = cumulative_speedup_write [i ] if i < len (cumulative_speedup_write ) else 0
113+ for i , library in enumerate (sorted_libraries ):
114+ read_speed = speed_read [i ] if i < len (speed_read ) else 0
115+ write_speed = speed_write [i ] if i < len (speed_write ) else 0
146116
147117 read_color = library_colors .get ((library , 'Read' ), 'gray' )
148118 write_color = library_colors .get ((library , 'Write' ), 'gray' )
149- font_size = max (8 , width * 30 )
150-
151- if read_speedup != 0 :
152- read_bar = ax .bar (i - width / 2 , read_speedup , label = f"{ library } Read" , color = read_color , width = width )
153- ax .text (i - width / 2 , read_speedup - read_speedup * 0.05 ,
154- f"{ read_speedup :.2f} MB/s" , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
155-
156- if write_speedup != 0 :
157- write_bar = ax .bar (i + width / 2 , write_speedup , label = f"{ library } Write" , color = write_color , width = width )
158- ax .text (i + width / 2 , write_speedup - write_speedup * 0.05 ,
159- f"{ write_speedup :.2f} MB/s" , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
160119
120+ font_size = max (8 , width * 30 )
161121
162- ax .set_xticks (range (len (libraries )))
163- ax .set_xticklabels (libraries )
164- ax .set_title (f'{ test_name } Result Speed Comparison' , color = 'white' )
122+ if read_speed != 0 and write_speed != 0 :
123+ ax .bar (i - width / 2 , read_speed , label = f"{ library } Read" , color = read_color , width = width )
124+ ax .bar (i + width / 2 , write_speed , label = f"{ library } Write" , color = write_color , width = width )
125+ elif read_speed != 0 :
126+ ax .bar (i , read_speed , label = f"{ library } Read" , color = read_color , width = width )
127+ elif write_speed != 0 :
128+ ax .bar (i , write_speed , label = f"{ library } Write" , color = write_color , width = width )
129+
130+ if read_speed != 0 :
131+ ax .text (i - width / 2 if write_speed != 0 else i , read_speed - 0.05 * read_speed ,
132+ f"{ read_speed :.2f} " + label_metric , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
133+ if write_speed != 0 :
134+ ax .text (i + width / 2 if read_speed != 0 else i , write_speed - 0.05 * write_speed ,
135+ f"{ write_speed :.2f} " + label_metric , ha = 'center' , va = 'top' , color = 'black' , fontsize = font_size , fontweight = 'bold' )
136+
137+ ax .set_xticks (range (len (sorted_libraries )))
138+ ax .set_xticklabels (sorted_libraries , ha = 'center' )
139+ ax .set_title (
140+ f"{ test_name } { 'Cumulative Speedup (Relative to Slowest Library)' if is_cumulative else 'Result Speed Comparison' } " ,
141+ color = 'white'
142+ )
165143 ax .set_xlabel ('Library Name' , color = 'white' )
166- ax .set_ylabel ('Result Speed (MB/s)' , color = 'white' )
167-
168- handles , labels = ax .get_legend_handles_labels ()
144+ ax .set_ylabel (y_label , color = 'white' )
145+
169146 for text in ax .get_xticklabels () + ax .get_yticklabels ():
170147 text .set_color ('lightgray' )
171-
148+
172149 ax .legend (title = 'Library and Result Type' , loc = 'best' )
173-
174- output_file_path_speedup = os .path .join (output_folder , f' { test_name } _Results .png' )
175- plt .savefig (output_file_path_speedup )
150+
151+ output_file_path = os .path .join (output_folder , f" { test_name } _ { 'Cumulative_Speedup' if is_cumulative else 'Results' } .png" )
152+ plt .savefig (output_file_path )
176153 plt .close ()
177154
178155def main ():
@@ -191,11 +168,11 @@ def main():
191168 raw_speed = get_raw_speeds (df )
192169
193170 cumulative_speedups = calculate_cumulative_speedup (df )
194-
195- plot_raw_comparisons (df , raw_speed , output_folder , test ["testName" ])
196-
197- plot_cumulative_speedup (df , cumulative_speedups , output_folder , test ["testName" ])
198-
171+
172+ plot_speed_results (df , raw_speed , output_folder , test ["testName" ], is_cumulative = False , y_label = "Result Speed (MB/s)" )
173+
174+ plot_speed_results (df , cumulative_speedups , output_folder , test ["testName" ], is_cumulative = True , y_label = "Cumulative Speedup (%)" , label_metric = "%" )
175+
199176 print (f'Graphs saved successfully for { test ["testName" ]} !' )
200177
201178if __name__ == "__main__" :
0 commit comments