python usage of timeit library

35 Views Asked by At

I'm trying to measure the execution time of my Python functions using the timeit library, and I'm looking to obtain output similar to the following:

"193 ms ± 33.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)"

Here is my code:

import timeit

def is_perfect(n):
    sum = 0
    for i in range(1, n):
        if n % i == 0:
            sum += i
    if sum == n:
        return True
    return False
0

There are 0 best solutions below