on-internet
← Community

Problem with decorators and how to measure the execution time of a function

Stack Overflow ·

I want to use this measure_time function as a decorator on get_num but it says NameError: name 'func' is not defined Is there another module or correction on this? I need a decorator to measure the time of execution of every function. def measure_time(func): def wrapper(): import timeit time=timeit.timeit('func()',number=1) print(time) return wrapper @measure_time def get_num(): listt=[] n=int(input()) for i in range(n+1): if i==0: continue listt.append(i) return listt print(get_num())

Comments

Sign in or sign up to comment and upvote.

No comments yet.