@@ -572,10 +572,6 @@ def determine_best_candidate(
572572 )
573573 speedup_ratios [candidate .optimization_id ] = perf_gain
574574
575- speedup_stats = compare_function_runtime_distributions (
576- original_code_runtime_distribution , candidate_runtime_distribution
577- )
578-
579575 tree = Tree (f"Candidate #{ candidate_index } - Sum of Minimum Runtimes" )
580576 if speedup_critic (
581577 candidate_result , original_code_baseline .runtime , best_runtime_until_now
@@ -609,28 +605,33 @@ def determine_best_candidate(
609605 console .print (tree )
610606 console .rule ()
611607
612- tree = Tree (f"Candidate #{ candidate_index } - Bayesian Bootstrapping Nonparametric Analysis" )
613- tree .add (
614- f"Expected candidate runtime (95% Credible Interval) = ["
615- f"{ humanize_runtime (candidate_runtime_statistics ['credible_interval_lower_bound' ])} , "
616- f"{ humanize_runtime (candidate_runtime_statistics ['credible_interval_upper_bound' ])} ], "
617- f"\n median = { humanize_runtime (candidate_runtime_statistics ['median' ])} "
618- f"\n Speedup ratio of candidate vs original:"
619- f"\n 95% Credible Interval = [{ speedup_stats ['credible_interval_lower_bound' ]:.3f} X, "
620- f"{ speedup_stats ['credible_interval_upper_bound' ]:.3f} X]"
621- f"\n median = { speedup_stats ['median' ]:.3f} X"
622- )
623- if speedup_stats ["credible_interval_lower_bound" ] > 1.0 :
624- tree .add ("The candidate is faster than the original code with a 95% probability." )
625- if speedup_stats ["median" ] > best_speedup_ratio_until_now :
626- best_speedup_ratio_until_now = speedup_stats ["median" ]
627- tree .add ("This candidate is the best candidate so far." )
608+ if candidate_runtime_distribution .any () and candidate_runtime_statistics :
609+ speedup_stats = compare_function_runtime_distributions (
610+ original_code_runtime_distribution , candidate_runtime_distribution
611+ )
612+ tree = Tree (f"Candidate #{ candidate_index } - Bayesian Bootstrapping Nonparametric Analysis" )
613+ tree .add (
614+ f"Expected candidate summed runtime (95% Credible Interval) = ["
615+ f"{ humanize_runtime (round (candidate_runtime_statistics ['credible_interval_lower_bound' ]))} "
616+ f", "
617+ f"{ humanize_runtime (round (candidate_runtime_statistics ['credible_interval_upper_bound' ]))} ]"
618+ f"\n Median = { humanize_runtime (round (candidate_runtime_statistics ['median' ]))} "
619+ f"\n Speedup ratio of candidate vs original:"
620+ f"\n 95% Credible Interval = [{ speedup_stats ['credible_interval_lower_bound' ]:.3f} X, "
621+ f"{ speedup_stats ['credible_interval_upper_bound' ]:.3f} X]"
622+ f"\n median = { speedup_stats ['median' ]:.3f} X"
623+ )
624+ if speedup_stats ["credible_interval_lower_bound" ] > 1.0 :
625+ tree .add ("The candidate is faster than the original code with a 95% probability." )
626+ if speedup_stats ["median" ] > best_speedup_ratio_until_now :
627+ best_speedup_ratio_until_now = float (speedup_stats ["median" ])
628+ tree .add ("This candidate is the best candidate so far." )
629+ else :
630+ tree .add ("This candidate is not faster than the current fastest candidate." )
628631 else :
629- tree .add ("This candidate is not faster than the current fastest candidate." )
630- else :
631- tree .add ("It is inconclusive whether the candidate is faster than the original code." )
632- console .print (tree )
633- console .rule ()
632+ tree .add ("It is inconclusive whether the candidate is faster than the original code." )
633+ console .print (tree )
634+ console .rule ()
634635
635636 self .write_code_and_helpers (original_code , original_helper_code , function_to_optimize .file_path )
636637 except KeyboardInterrupt as e :
@@ -1087,9 +1088,6 @@ def establish_original_code_baseline(
10871088 console .rule ()
10881089
10891090 total_timing = benchmarking_results .total_passed_runtime () # caution: doesn't handle the loop index
1090- runtime_distribution , runtime_statistics = benchmarking_results .bayesian_nonparametric_bootstrap_analysis (
1091- 100_000
1092- )
10931091 functions_to_remove = [
10941092 result .id .test_function_name
10951093 for result in behavioral_results
@@ -1123,9 +1121,12 @@ def establish_original_code_baseline(
11231121 console .rule ()
11241122 logger .debug (f"Total original code summed runtime (ns): { total_timing } " )
11251123 console .rule ()
1124+ runtime_distribution , runtime_statistics = benchmarking_results .bayesian_nonparametric_bootstrap_analysis (
1125+ 100_000
1126+ )
11261127 logger .info (
11271128 f"Bayesian Bootstrapping Nonparametric Analysis"
1128- f"\n Expected original code runtime (95% Credible Interval) = ["
1129+ f"\n Expected original code summed runtime (95% Credible Interval) = ["
11291130 f"{ humanize_runtime (round (runtime_statistics ['credible_interval_lower_bound' ]))} , "
11301131 f"{ humanize_runtime (round (runtime_statistics ['credible_interval_upper_bound' ]))} ], "
11311132 f"\n median: { humanize_runtime (round (runtime_statistics ['median' ]))} "
@@ -1245,18 +1246,23 @@ def run_optimized_candidate(
12451246 if (total_candidate_timing := candidate_benchmarking_results .total_passed_runtime ()) == 0 :
12461247 logger .warning ("The overall test runtime of the optimized function is 0, couldn't run tests." )
12471248 console .rule ()
1248- runtime_distribution , runtime_statistics = (
1249- candidate_benchmarking_results .bayesian_nonparametric_bootstrap_analysis (100_000 )
1250- )
1251-
1252- logger .debug (f"Total optimized code { optimization_candidate_index } runtime (ns): { total_candidate_timing } " )
1253- console .rule ()
1254- logger .debug (
1255- f"Overall code runtime (95% Credible Interval) = ["
1256- f"{ humanize_runtime (round (runtime_statistics ['credible_interval_lower_bound' ]))} , "
1257- f"{ humanize_runtime (round (runtime_statistics ['credible_interval_upper_bound' ]))} ], median: "
1258- f"{ humanize_runtime (round (runtime_statistics ['median' ]))} "
1259- )
1249+ runtime_distribution : npt .NDArray [np .float64 ] = np .array ([])
1250+ runtime_statistics : dict [str , np .float64 ] = {}
1251+ else :
1252+ logger .debug (
1253+ f"Total optimized code { optimization_candidate_index } runtime (ns): { total_candidate_timing } "
1254+ )
1255+ console .rule ()
1256+ runtime_distribution , runtime_statistics = (
1257+ candidate_benchmarking_results .bayesian_nonparametric_bootstrap_analysis (100_000 )
1258+ )
1259+ logger .debug (
1260+ f"Overall code summed runtime (95% Credible Interval) = ["
1261+ f"{ humanize_runtime (round (runtime_statistics ['credible_interval_lower_bound' ]))} , "
1262+ f"{ humanize_runtime (round (runtime_statistics ['credible_interval_upper_bound' ]))} ], median: "
1263+ f"{ humanize_runtime (round (runtime_statistics ['median' ]))} "
1264+ )
1265+ console .rule ()
12601266 return Success (
12611267 (
12621268 OptimizedCandidateResult (
0 commit comments