Created
November 15, 2023 10:41
-
-
Save pprzetacznik/019b427ef5b6dec7b5bb5eed8fb59c42 to your computer and use it in GitHub Desktop.
timeit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from pytest import fixture | |
def timeit(iterations_num=10_000): | |
def wrapper(fun): | |
def nested_wrapper(*args, **kwargs): | |
start = time.time() | |
for i in range(iterations_num): | |
result = fun(*args, **kwargs) | |
stop = time.time() | |
total = stop - start | |
print(f"total time spend: {total}s") | |
return result | |
return nested_wrapper | |
return wrapper | |
@timeit() | |
def fun1(input_list, lambda_fun): | |
return list(map(lambda_fun, input_list)) | |
@timeit() | |
def fun2(input_list, lambda_fun): | |
return [str(t + 1) for t in input_list] | |
@fixture | |
def input_lambda(): | |
return lambda t: str(t + 1) | |
@fixture | |
def input_list(): | |
return range(1000) | |
def test_map(input_list, input_lambda): | |
fun1(input_list, input_lambda) | |
fun2(input_list, input_lambda) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment