Caching / Memoization
Dùng để lưu kết quả tạm để tránh tính toán lại:
from functools import lru_cache
@lru_cache(maxsize=128)
def slow_function(x):
print(f"Calculating {x}")
return x * x
Dùng để lưu kết quả tạm để tránh tính toán lại:
from functools import lru_cache
@lru_cache(maxsize=128)
def slow_function(x):
print(f"Calculating {x}")
return x * x
Không có bình luận