0

How can I convert the execution time to milliseconds. I already multiplied the start and end time to 1000.

I used time.time()

Execution Time

Result: ('Start time: ', 1596465418538.365)

Remove.IntNonIdUniqueIndex

('End time: ', 1596465418538.399)

('Execution time: ', 3.409385681152344e-05)

  • This is answered [here](https://stackoverflow.com/questions/766335/python-speed-testing-time-difference-milliseconds) – RakeshV Aug 03 '20 at 14:52

2 Answers2

1

time.time() basic unit is second. It's enough to multiply the difference between end and start by 1000 to get the milliseconds.

import time

start = time.time()
time.sleep(1)
end = time.time()
d = end - start
print(f'executed in {d} seconds or {d*1000} milliseconds')

executed in 1.003673791885376 seconds or 1003.673791885376 milliseconds
alec_djinn
  • 10,104
  • 8
  • 46
  • 71
0

If you are measuring program execution times, it is best to use time.monotonic() or time.monotonic_ns(). These functions are guaranteed never to go backwards even in the event of system clock updates.

The first returns a value in seconds, the second in nanoseconds.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94