performance - Comment mesurer le temps écoulé en Python

Mots clés : pythonperformancemeasuretimeitpython

meilleur 5 Réponses performance - Comment mesurer le temps écoulé en Python

vote vote

95

import time  start = time.time() print("hello") end = time.time() print(end - start) 
vote vote

88

from timeit import default_timer as timer  start = timer() # ... end = timer() print(end - start) # Time in seconds, e.g. 5.38091952400282 
vote vote

72

import time  t = time.process_time() #do some stuff elapsed_time = time.process_time() - t 
vote vote

69

from timeit import default_timer as timer from datetime import timedelta  start = timer()  # .... # (your code runs here) # ...  end = timer() print(timedelta(seconds=end-start)) 
0:00:01.946339 
vote vote

55

def foo():      # print "hello"        return "hello" 
% python -mtimeit -s'import test' 'test.foo()' 1000000 loops, best of 3: 0.254 usec per loop 

Questions similaires