Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding code profiler into our code base #1435

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Adding code profiler into our code base #1435

wants to merge 2 commits into from

Conversation

mgtm98
Copy link
Collaborator

@mgtm98 mgtm98 commented Nov 8, 2024

Description

A utils class that can be used to profile the python code.

time_function: A decorator that prints the time taken by a decorated function.
start_marker: Starts a timer for a section of code, identified by a unique name.
end_marker: Ends the timer for a given section and prints the time taken.

@marsninja
Copy link
Contributor

Hey, here is how you do the type annotation, try chatgpt for more info @mgtm98

from typing import Callable, TypeVar, ParamSpec

P = ParamSpec("P")
R = TypeVar("R")

def decorator(func: Callable[P, R]) -> Callable[P, R]:
    def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
        print(f"Called with args={args}, kwargs={kwargs}")
        return func(*args, **kwargs)
    return wrapper

@decorator
def example_function(x: int, y: str) -> str:
    return f"{x} and {y}"

result = example_function(1, "hello")  # Logs args and kwargs
print(result)  # Output: "1 and hello"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants