יום שישי, 12 ביולי 2013

functools.lru_cache

A sample program that demonstrates the functools.lru_cache:

  1: import timeit 
  2: import itertools
  3: import functools
  4: import sys
  5: 
  6: @functools.lru_cache(maxsize=32)
  7: def myTestCacheFucntion (pKey  ):
  8:     print ("The method has been called")
  9:     return "Hello:" + pKey
 10: 
 11: print ( myTestCacheFucntion ("Zvika"))
 12: 
 13: print (myTestCacheFucntion ("Shahf"))
 14: 
 15: print (myTestCacheFucntion ("Zvika"))
 16: 
 17: print (myTestCacheFucntion ("Shahf"))
 18: 
 19: sys.exit()

And the result
The method has been called
Hello:Zvika
The method has been called
Hello:Shahf
Hello:Zvika
Hello:Shahf
Traceback (most recent call last):
  File "C:\blogs\test1\testpy.py", line 19, in <module>
    sys.exit()
SystemExit

אין תגובות:

הוסף רשומת תגובה