there is a thing I want to eliminate, it is when the function print to output, I know about overriding sys.stdout.write
which print()
function uses. but I think this isn't an ideal fix for this. I'm looking for the ideal pythonic way for doing this?
from timeit import Timer
from functools import partial
def timing_decorator(function):
def wrapper(*args, **kwargs):
# print(function)
callable_f = partial(function, *args, **kwargs)
# print(dir(Timer))
total = Timer(callable_f).timeit(1)
print(total)
return total
return wrapper
# example function
@timing_decorator
def hello(arg):
print(arg)
return
hello('hi')
This outputs:
hi
0.00036
My expected output would be:
0.00036