-1
I want to calculate the execution time of a function in nanoseconds, thus:
tempoIniAlg = time_ns()
vetorOrdenado = quickSort(vetor) # Vetor ordenado
tempoAlg = time_ns() # Tempo de resolução do algortimo
The problem is that with a relatively high frequency, the fields tempoIniAlg
and tempoAlg
have exactly the same value, resulting in 0 the difference value between both, which is impossible for N reasons. I tried to do it this way and it didn’t solve anything:
tempoIniAlg = time_ns()
vetorOrdenado = quickSort(vetor) # Vetor ordenado
tempoAlg = time_ns() - tempoIniAlg # Tempo de resolução do algortimo
I have no idea what it might be.
If you want to measure runtime, you can use the module
timeit
: https://docs.python.org/3/library/timeit.html– hkotsubo