-2

I am writing a program in python and I want to calculate the execution time of more than one function in my program and I get the calculated time equal to 0.0!! why this is occurring, please? Note that I used more than one approach in calculation using time and DateTime modules and get the same results. This is an example of my code :

import time
t1 = time.time()
keys = RSA.generateKey(K) # calling user define function 
t2 = time.time()
print(" key generat: ", t2 - t1)

output:

key generat:  0.0

Shouldn't there be a time difference even if it is very small?

  • 1
    `time.time()` is only accurate to the second. If it takes less than a second you'll get 0. – Barmar Mar 11 '21 at 21:22

1 Answers1

1

Using datetime module you can calculate time taken to execute function.

from datetime import datetime
start = datetime.now()
# function()
t = datetime.now() - start
print(t)
Rima
  • 1,447
  • 1
  • 6
  • 12