MCPcopy Index your code
hub / github.com/evalplus/evalplus / profile

Function profile

evalplus/perf/profile.py:132–183  ·  view source on GitHub ↗

Profile the func_code against certain input tests. The function code is assumed to be correct and if a string is returned, it is an error message.

(
    func_code: str,
    entry_point: str,
    test_inputs: List[Any],
    timeout_second_per_test: float,
    memory_bound_gb: int = PERF_RAM_GB_PER_PROC,
    profile_rounds: int = PERF_PROFILE_ROUNDS,
    profiler: Callable = num_instruction_profiler,
    warmup_inputs: Optional[List[Any]] = None,  # multiple inputs
)

Source from the content-addressed store, hash-verified

130
131
132def profile(
133 func_code: str,
134 entry_point: str,
135 test_inputs: List[Any],
136 timeout_second_per_test: float,
137 memory_bound_gb: int = PERF_RAM_GB_PER_PROC,
138 profile_rounds: int = PERF_PROFILE_ROUNDS,
139 profiler: Callable = num_instruction_profiler,
140 warmup_inputs: Optional[List[Any]] = None, # multiple inputs
141) -> List[int | float | str]:
142 """Profile the func_code against certain input tests.
143 The function code is assumed to be correct and if a string is returned, it is an error message.
144 """
145 timeout = timeout_second_per_test * len(test_inputs) * profile_rounds
146
147 def _run():
148 compute_cost = Value("d", 0.0)
149 progress = Value("i", _STAT_NONE)
150
151 p = Process(
152 target=get_instruction_count_shared_mem,
153 args=(
154 profiler,
155 func_code,
156 entry_point,
157 test_inputs,
158 timeout_second_per_test,
159 memory_bound_gb,
160 warmup_inputs,
161 # shared memory
162 compute_cost,
163 progress,
164 ),
165 )
166 p.start()
167 p.join(timeout=timeout + 1)
168 if p.is_alive():
169 p.terminate()
170 time.sleep(0.1)
171
172 if p.is_alive():
173 p.kill()
174 time.sleep(0.1)
175
176 if progress.value == _STAT_SUCC:
177 return compute_cost.value
178 elif progress.value == _STAT_NONE:
179 return "PROFILING DID NOT START"
180 elif progress.value == _STAT_ERROR:
181 return "SOLUTION ERROR ENCOUNTERED WHILE PROFILING"
182
183 return [_run() for _ in range(profile_rounds)]

Callers 3

get_avg_ref_profileFunction · 0.90
perf_workerFunction · 0.90
scriptFunction · 0.90

Calls 1

_runFunction · 0.85

Tested by

no test coverage detected