It is a function that measures methods and functions as a whole. It's python2.7.
Put the number of repetitions at the end of the argument
import time
def timer_handler(func, *args):
    #As pointed out by hiracamus, time.time()Fixed from
    start = time.clock() 
    count = args[-1]
    args2 = args[:-1]
    for i in range(count):
        rtn = func(*args2)
    elapsed_time = time.clock() - start
    print("time = " + str(elapsed_time))
    return rtn
Processing time when executed 10,000 times repeatedly
def test(a,b,c):
    return pow(a,pow(b,c))
loop = 10000
v = timer_handler(test, 2,3,3, loop)
print v
time = 0.024491071701 134217728
Recommended Posts