How to print the calculation execution time executed in tensorflow code?

This is a common question.

I wrote a piece of code in which the tensorflow function is computed to calculate.

I want to print the time taken to execute the code.

At first I used:

import time
start = time.time()
main()
print ("%s"  % (time.time() - start_time))

But I read that this is an inaccurate way to measure runtime.

How to accurately measure the runtime of my program.

+4
source share
1 answer

time.perf_counter(). perf_counter " ". undefined ( ), . . .

time.time() - Unix (1 1970 ) , .

time.time() time.perf_counter(), .

import time
start = time.perf_counter()
main()
elapsed = time.perf_counter() - start
print('Elapsed %.3f seconds.' % elapsed)
# The .3f is to round to 3 decimal places.
+5

Source: https://habr.com/ru/post/1667588/


All Articles