Skip to content

Commit b568597

Browse files
⚡️ Speed up function generate__notify by 38%
To optimize the given Python program, let's focus on the processing inside the loop and avoid redundant operations. 1. The function `flag_env()` is called multiple times within the nested loop, which introduces unnecessary redundancy. 2. Since `flag_env()` computes the same result every time it's called, we can compute it once and reuse the result. 3. Let's apply these optimizations. Here's the optimized version of your program. In this optimized version. - The `flag_env()` is called once and its result is stored in `flag_value` within the `add_flag_env` function, thereby avoiding multiple redundant calls. - This reduces the overall time complexity and improves the program’s runtime performance. This refactoring maintains the functionality while optimizing for performance.
1 parent 229d461 commit b568597

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bench_runner/scripts/install.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ def flag_env():
9999

100100

101101
def add_flag_env(jobs: dict[str, Any]):
102+
flag_value = flag_env() # Compute flag_env once and reuse the result
102103
for job in jobs.values():
103104
if "steps" in job:
104105
job.setdefault("env", {})
105-
job["env"]["flags"] = flag_env()
106+
job["env"]["flags"] = flag_value
106107
for step in job["steps"]:
107108
if "run" in step:
108-
step["run"] = step["run"].replace("${{ env.flags }}", flag_env())
109+
step["run"] = step["run"].replace("${{ env.flags }}", flag_value)
109110

110111

111112
def generate__benchmark(src: Any) -> Any:

0 commit comments

Comments
 (0)