API reference
Core
microbench.MicroBench
Source code in microbench/__init__.py
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 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
output_result(bm_data)
Output result to self.outfile as a line in JSON format
Source code in microbench/__init__.py
microbench.MicroBenchRedis
Bases: MicroBench
Source code in microbench/__init__.py
Mixins
microbench.MBFunctionCall
Capture function arguments and keyword arguments
Source code in microbench/__init__.py
microbench.MBReturnValue
microbench.MBPythonVersion
Capture the Python version and location of the Python executable
Source code in microbench/__init__.py
microbench.MBHostInfo
Capture the hostname and operating system
Source code in microbench/__init__.py
microbench.MBHostCpuCores
Bases: _NeedsPsUtil
Capture the number of logical CPU cores
Source code in microbench/__init__.py
microbench.MBHostRamTotal
Bases: _NeedsPsUtil
Capture the total host RAM in bytes
Source code in microbench/__init__.py
microbench.MBGlobalPackages
Capture Python packages imported in global environment
Source code in microbench/__init__.py
microbench.MBInstalledPackages
Capture installed Python packages using importlib.
Records the name and version of every distribution available in the
current Python environment via importlib.metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
capture_paths |
bool
|
Also record the installation path of each
package under |
Source code in microbench/__init__.py
microbench.MBCondaPackages
Capture conda packages using the conda CLI.
Requires conda to be available on PATH. Captures all packages
in the active conda environment (determined by sys.prefix).
Attributes:
| Name | Type | Description |
|---|---|---|
include_builds |
bool
|
Include the build string in the version.
Defaults to |
include_channels |
bool
|
Include the channel name in the version.
Defaults to |
Source code in microbench/__init__.py
microbench.MBNvidiaSmi
Capture attributes on installed NVIDIA GPUs using nvidia-smi.
Requires the nvidia-smi utility to be available on PATH
(bundled with NVIDIA drivers).
Results are stored as nvidia_<attr> fields, each a dict keyed by
GPU UUID. Run nvidia-smi --help-query-gpu for all available
attribute names. Run nvidia-smi -L to list GPU UUIDs.
Attributes:
| Name | Type | Description |
|---|---|---|
nvidia_attributes |
tuple[str]
|
Attributes to query. Defaults to
|
nvidia_gpus |
tuple
|
GPU IDs to poll — zero-based indexes, UUIDs, or PCI bus IDs. GPU UUIDs are recommended (indexes can change after a reboot). Omit to poll all installed GPUs. |
Source code in microbench/__init__.py
microbench.MBLineProfiler
Run the line profiler on the selected function
Requires the line_profiler package. This will generate a benchmark which times the execution of each line of Python code in your function. This will slightly slow down the execution of your function, so it's not recommended in production.
Source code in microbench/__init__.py
decode_line_profile(line_profile_pickled)
staticmethod
Decode a base64-encoded pickled line profiler result.
Security note: This uses pickle.loads, which can execute arbitrary code. Only call this on data from a trusted source (e.g. your own benchmark output files). Do not decode line profile data received over a network or from an untrusted file.
Source code in microbench/__init__.py
JSON encoding
microbench.JSONEncoder
Bases: JSONEncoder