landingai.timer
Timer class for timing code execution and reporting results.
Timer
dataclass
Bases: ContextDecorator
Time your code using a class, context manager, or decorator. See below examples for usage. As a class:
As a context manager:
As a decorator:
All the time values are stored in a global dictionary, accessible via the stats
attribute.
See the TimerStats
class for more information.
Source code in landingai/timer.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
__enter__()
__exit__(*exc_info)
start()
Start a new timer.
Source code in landingai/timer.py
stop()
Stop the timer, and report the elapsed time.
Source code in landingai/timer.py
TimerStats
Custom dictionary that stores time values of different timers. For each timer, it stores a sequence of time duration values. Each sequence is limited to a maximum size to avoid memory issues.
Source code in landingai/timer.py
__init__(*args, **kwargs)
Add a private dictionary keeping track of all timings
__repr__()
Return a string representation of the TimerStats.
add(name, value)
apply(func, name)
Apply a function to the results of one named timer.
clear()
count(name)
max(name)
mean(name)
median(name)
min(name)
stats(name)
All the stats for a given timer.