Timer Module¶
wraptimer.timer ¶
Copyright (c) 2023 Anthony Mugendi
This software is released under the MIT License. https://opensource.org/licenses/MIT
Timer ¶
Timer Class.¶
This class helps you to create high precision timers to measure any code processes.
Args:¶
-
timer_type
(Literal[, optional): Determines what clock is used. Defaults to "performance".timer_type
can only take the following string values:- "performance": the most precise clock in the system.
- "process": measures the CPU time, meaning sleep time is not measured.
- "long_running": it is an increasing clock that do not change when the date and or time of the machine is changed.
-
disable_garbage_collect
(bool, optional): Determines if garbage collection is disabled.Defaults to True.
Note
With high precision timers, it is best to disable garbage collection so that it does not affect how long the code actually takes to run.
Example Usage¶
Source code in wraptimer/timer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 |
|
time_microsec
property
¶
Get number of microseconds taken from start() to stop().
Returns:
float
: microseconds as a float
time_millisec
property
¶
Get number of milliseconds taken from start() to stop().
Returns:
float
: milliseconds as a float
time_nanosec
property
¶
Get number of nanoseconds taken from start() to stop().
Returns:
float
: nanoseconds as a float
time_sec
property
¶
Get number of seconds taken from start() to stop().
Returns:
float
: seconds as a float
time_string
property
¶
Get human readable duration taken from start() to stop().
Returns:
str
: human readable duration
time_units
property
¶
Get dictionary of time taken from start() to stop().
Returns:
float
: nanoseconds as a float