28 lines
549 B
Python
28 lines
549 B
Python
from functools import wraps
|
|
import time
|
|
|
|
|
|
def timing(func):
|
|
"""Decorator zur Messung der Ausführungszeit einer Funktion."""
|
|
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
start_time = time.perf_counter()
|
|
result = func(*args, **kwargs)
|
|
end_time = time.perf_counter()
|
|
elapsed = end_time - start_time
|
|
print(f"[{func.__name__}] Laufzeit: {elapsed:.6f} Sekunden")
|
|
return result
|
|
|
|
return wrapper
|
|
|
|
from timing import timing
|
|
|
|
|
|
@timing
|
|
def beispiel_funktion():
|
|
"""Dies ist eine Testfunktion."""
|
|
pass
|
|
|
|
|
|
help(beispiel_funktion) |