from typing import Callable
import functools
import time


def timer(f: Callable) -> Callable:
    """Decorator to log the time for function f to execute."""

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        """Wrapper function to log time of execution of function f."""
        start = time.time()
        result = f(*args, **kwargs)
        time_elapsed = time.time() - start
        lasted_in_seconds = time_elapsed >= 1

        print(
            "Function: {}() Time Elapsed: {:.5f}{}".format(
                f.__name__,
                time_elapsed if lasted_in_seconds else time_elapsed * 1000,
                "s" if lasted_in_seconds else "ms",
            )
        )

        return result

    return wrapper