Why does function takes zero seconds to execute

Viewed 204

I have written the following code where I average the rows of a frame. I wanted to test the speed and compare it with using np.mean.

@jit(nopython=True)
def test(frame):
    #np.mean(frame, axis=1)
    
    averages = []
    for i in range(480):
        summation = 0
        for j in range(640):
            summation += frame[i, j, 1]

        averages.append(summation/640)
    return averages

while True:
     a = time.time()
     test(frame)
     print("My program took {:.15f} seconds to run".format(time.time() - a))

When using np.mean(), I get average time around 6ms. When I remove it and use numba, the first iteration takes 100ms, but the subsequent take 0.000000000s. I want to know the exact speed of the code when using numba, because I am certain it doesn't take 0s to execute the code.

1 Answers

time.time() - a is 0ms in your case maybe because there is no return value at the end of your function.

Try adding return averages at the end of the function in order to return a calculated value.

Related