Skip to content

Commit

Permalink
addimg new profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Fadi88 committed Dec 13, 2024
1 parent f7a089e commit c3b5053
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions 2024/day14/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@


def profiler(method):
from time import perf_counter_ns

def wrapper_method(*args: Any, **kwargs: Any) -> Any:
t = perf_counter()
start_time = perf_counter_ns()
ret = method(*args, **kwargs)
print(f"Method {method.__name__} took : {perf_counter() - t:.3f} sec")
stop_time = perf_counter_ns() - start_time
time_len = min(9, ((len(str(stop_time))-1)//3)*3)
time_conversion = {9: 'seconds', 6: 'milliseconds',
3: 'microseconds', 0: 'nanoseconds'}
print(f"Method {method.__name__} took : {
stop_time / (10**time_len)} {time_conversion[time_len]}")
return ret

return wrapper_method
Expand Down

0 comments on commit c3b5053

Please sign in to comment.