⚡ Bolt: Optimize redundant iteration in get_completed_reports_count (#115)
Optimized `get_completed_reports_count` to iterate over active report sections directly instead of checking all possible sections, improving performance. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
This commit is contained in:
parent
8efcf2a58e
commit
df5de732cf
33
benchmark.py
33
benchmark.py
|
|
@ -1,33 +0,0 @@
|
|||
import time
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
# We want to benchmark the difference between iterating with a list comprehension
|
||||
# vs vectorized str.lower() method for pd.DataFrame column manipulation.
|
||||
|
||||
# Let's create a DataFrame with many columns to see the difference clearly.
|
||||
# For a typical stock dataframe, the number of columns is small (e.g. 6-7).
|
||||
# Let's benchmark for both a small DataFrame and a very large DataFrame.
|
||||
|
||||
def benchmark(num_cols, iterations):
|
||||
cols = [f"Col_{i}" for i in range(num_cols)]
|
||||
df = pd.DataFrame(columns=cols)
|
||||
|
||||
start = time.time()
|
||||
for _ in range(iterations):
|
||||
_ = [str(c).lower() for c in df.columns]
|
||||
t1 = time.time() - start
|
||||
|
||||
start = time.time()
|
||||
for _ in range(iterations):
|
||||
_ = df.columns.astype(str).str.lower()
|
||||
t2 = time.time() - start
|
||||
|
||||
print(f"Num cols: {num_cols}, Iterations: {iterations}")
|
||||
print(f"List comprehension: {t1:.6f} s")
|
||||
print(f"Pandas str.lower(): {t2:.6f} s")
|
||||
print("-" * 30)
|
||||
|
||||
benchmark(10, 10000)
|
||||
benchmark(100, 10000)
|
||||
benchmark(1000, 10000)
|
||||
|
|
@ -140,10 +140,13 @@ class MessageBuffer:
|
|||
|
||||
This prevents interim updates (like debate rounds) from counting as completed.
|
||||
"""
|
||||
# Optimized: Iterate over active report sections directly instead of all possible sections,
|
||||
# checking content first to short-circuit the finalizing agent status lookup.
|
||||
count = 0
|
||||
for section, (_, finalizing_agent) in self.REPORT_SECTIONS.items():
|
||||
if self.report_sections.get(section) is not None:
|
||||
if self.agent_status.get(finalizing_agent) == "completed":
|
||||
for section, content in self.report_sections.items():
|
||||
if content is not None:
|
||||
section_info = self.REPORT_SECTIONS.get(section)
|
||||
if section_info and self.agent_status.get(section_info[1]) == "completed":
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue