Profiler¶
-
class
sorts.profiling.
Profiler
(distribution=False, track_memory=False, snapshot_total=True)[source]¶ Bases:
object
Performance profiler class.
The named performance control is especially useful for timing contents of loops.
Usage example:
p = Profiler() p.start('list init') p.start('program') lst = list(range(200)) p.stop('list init') for i in range(1000): p.start('list reversal') lst = lst[::-1] p.stop('list reversal') p.stop('program') print(p)
Methods
__init__
([distribution, track_memory, …])Initialize self.
fmt
([normalize, timedelta])Format summary of the profiler into a string.
from_txt
(path)mean
([name])memory_diff
(name[, save])Calculate a memory difference between the latest snapshot and now.
snapshot
(name)Take a tracemalloc snapshot.
start
(name)Records a start time for named call.
stop
(name)Records a time elapsed since the latest start time for named call.
to_txt
(path)total
([name])