def print_result_from_timeit ( stmt = 'pass' , setup = 'pass' , number = 1000000 ) : units = [ "s" , "ms" , "us" , "ns" ] duration = timeit ( stmt , setup , number = int ( number ) ) avg_duration = duration / float ( number ) thousands = int ( math . floor ( math . log ( avg_duration , 1000 ) ) ) print ( "Total time: %fs. Average run: %.3f%s." % ( duration , avg_duration * ( 1000 ** - thousands ) , units [ - thousands ] ) )
how to measure the execute time in python
Clean function to know how much time took the execution of one statement
def print_result_from_timeit(stmt='pass', setup='pass', number=1000000):
    """
    Clean function to know how much time took the execution of one statement
    """
    units = ["s", "ms", "us", "ns"]
    duration = timeit(stmt, setup, number=int(number))
    avg_duration = duration / float(number)
    thousands = int(math.floor(math.log(avg_duration, 1000)))

    print("Total time: %fs. Average run: %.3f%s." % (
        duration, avg_duration * (1000 ** -thousands), units[-thousands]))