Skip to content

Commit

Permalink
create auxillary function to refactor while loop
Browse files Browse the repository at this point in the history
The existing logic was quite hard to read - to make future maintenance easier, the logic
is broken up a bit to use explicit variable names, bundled in a single auxillary function
  • Loading branch information
schroeding committed Jan 12, 2025
1 parent dcced78 commit 24a9afc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions benchexec/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,17 @@ def calculate_chosen_level(
@return: calculated chosen level as index
"""

def next_level_suitable(chosen_level, hierarchy_levels, core_limit):
"""Check if its possible to proceed to the next hierarchy level."""
if chosen_level >= len(hierarchy_levels) - 1:
return False # Already at the last level
current_level_values = next(iter(hierarchy_levels[chosen_level].values()))
return len(current_level_values) < core_limit

chosen_level = 1
# move up in hierarchy as long as the number of cores at the current level is smaller than the coreLimit
# if the number of cores at the current level is as big as the coreLimit: exit loop
while (
chosen_level < len(hierarchy_levels) - 1
and len(next(iter(hierarchy_levels[chosen_level].values())))
< coreLimit_rounded_up
):
while next_level_suitable(chosen_level, hierarchy_levels, coreLimit_rounded_up):
chosen_level = chosen_level + 1
return chosen_level

Expand Down

0 comments on commit 24a9afc

Please sign in to comment.