Function cache in python

technical talkiess
0

 Function cache :- 

Isse program fast run hota hai 

Max size ko save kar leta hai isme 


import time

from functools import lru_cache


# lru cache ek decorators hota hai


@lru_cache(maxsize=3)

# max sizse ke according ye value save kar lenga

# uske according value ko cache kar denga


def testing_cache(n):

    # yaha par wo n time tak sleep hoga ..... aur utna time lenga run hone ke liye

    time.sleep(n)


    return n



if __name__ == '__main__':

    # agar aap is fnction ko jitne bar run karte ho utni bar wo time lenga run hone ke liye


    print("Done")

    print(testing_cache(12))

    print("Done")

    print(testing_cache(1))

    print("Done")

    print(testing_cache(1))

    print("Done")

    # upper vali 3 value alag thi to e 4 seconds lenga isme

    print(testing_cache(4))

    print("Done")

   



Function cache practice :- 


print("Enter the cache limit ")

sizelimit = int(input())

print("Enter first number here ")

a = int(input())

print("Enter second number here ")

b = int(input())



from functools import lru_cache


@lru_cache(maxsize=sizelimit)

def function_call(a,b):

    return a+b





print(function_call(a,b))
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)