CKTIS / Python
Modul cProfile
Profilira kod bilježenjem poziva, njihova broja i vremena.
Verzija: Python 3.14; repository image, production runtime not attested
Sintaksa
cProfile.Profile().runcall(function, *args)Profilira kod bilježenjem poziva, njihova broja i vremena.
Razlikuje vlastito vrijeme i ukupno vrijeme s podpozivima, a pstats obrađuje podatke. Mjerenje stvara dodatni trošak i trajanja se razlikuju.
Rezultat računa i tri poziva square stabilni su.
Primjeri
import cProfile
import pstats
def square(x):
return x * x
def workload():
return sum(square(i) for i in (1, 2, 3))
profile = cProfile.Profile()
print(profile.runcall(workload))
stats = pstats.Stats(profile)
print(next(row[1] for key, row in stats.stats.items() if key[2] == "square"))
Rezultat
14 3
Rezultat računa i tri poziva square stabilni su.