Skip to content

Commit ce1445c

Browse files
committed
Update function_optimizer.py
1 parent 08a3412 commit ce1445c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,18 @@ def determine_best_candidate(
593593
)
594594
tree.add(f"Speedup percentage: {perf_gain * 100:.1f}%")
595595
tree.add(f"Speedup ratio: {perf_gain + 1:.3f}X")
596+
if (
597+
original_code_baseline.async_throughput is not None
598+
and candidate_result.async_throughput is not None
599+
):
600+
from codeflash.result.critic import throughput_gain
601+
throughput_gain_value = throughput_gain(
602+
original_throughput=original_code_baseline.async_throughput,
603+
optimized_throughput=candidate_result.async_throughput,
604+
)
605+
tree.add(f"Original async throughput: {original_code_baseline.async_throughput} executions")
606+
tree.add(f"Optimized async throughput: {candidate_result.async_throughput} executions")
607+
tree.add(f"Throughput improvement: {throughput_gain_value * 100:.1f}%")
596608
line_profile_test_results = self.line_profiler_step(
597609
code_context=code_context,
598610
original_helper_code=original_helper_code,
@@ -628,6 +640,7 @@ def determine_best_candidate(
628640
replay_performance_gain=replay_perf_gain if self.args.benchmark else None,
629641
winning_benchmarking_test_results=candidate_result.benchmarking_test_results,
630642
winning_replay_benchmarking_test_results=candidate_result.benchmarking_test_results,
643+
async_throughput=candidate_result.async_throughput,
631644
)
632645
valid_optimizations.append(best_optimization)
633646
# queue corresponding refined optimization for best optimization
@@ -652,6 +665,16 @@ def determine_best_candidate(
652665
)
653666
tree.add(f"Speedup percentage: {perf_gain * 100:.1f}%")
654667
tree.add(f"Speedup ratio: {perf_gain + 1:.3f}X")
668+
if (
669+
original_code_baseline.async_throughput is not None
670+
and candidate_result.async_throughput is not None
671+
):
672+
from codeflash.result.critic import throughput_gain
673+
throughput_gain_value = throughput_gain(
674+
original_throughput=original_code_baseline.async_throughput,
675+
optimized_throughput=candidate_result.async_throughput,
676+
)
677+
tree.add(f"Throughput gain: {throughput_gain_value * 100:.1f}%")
655678

656679
if is_LSP_enabled():
657680
lsp_log(LspMarkdownMessage(markdown=tree_to_markdown(tree)))
@@ -695,6 +718,7 @@ def determine_best_candidate(
695718
replay_performance_gain=valid_opt.replay_performance_gain,
696719
winning_benchmarking_test_results=valid_opt.winning_benchmarking_test_results,
697720
winning_replay_benchmarking_test_results=valid_opt.winning_replay_benchmarking_test_results,
721+
async_throughput=valid_opt.async_throughput,
698722
)
699723
valid_candidates_with_shorter_code.append(new_best_opt)
700724
diff_lens_list.append(

0 commit comments

Comments
 (0)