Created
September 20, 2019 22:53
-
-
Save rtorresve/018de3fc0b072369625575e2cad9f1a7 to your computer and use it in GitHub Desktop.
Using python cache
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 functools import lru_cache | |
@lru_cache() | |
def task(a,b): | |
print('Init task') | |
time.sleep(2) | |
return a + b | |
task.cache_clear() | |
start = time.time() | |
print(task(10,10)) | |
print(task(10,10)) | |
print(task(10,15)) | |
print(task(10,10)) | |
print(task(10,10)) | |
print(task(10,10)) | |
print(task(10,15)) | |
print(f'total time {time.time() - start}') | |
print(task.cache_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment