Benchmarking#
PyLops-MPI users can convenienly benchmark the performance of their code with a simple decorator.
pylops_mpi.utils.benchmark
and pylops_mpi.utils.mark
support various
function calling patterns that may arise when benchmarking distributed code.
pylops_mpi.utils.benchmark
is a decorator used to time the execution of entire functions.pylops_mpi.utils.mark
is a function used inside decorated functions to insert fine-grained time measurements.
Note
This benchmark utility is enabled by default i.e., if the user decorates the function with @benchmark
, the function will go through
the time measurements, adding overheads. Users can turn off the benchmark while leaving the decorator in-place with
>> export BENCH_PYLOPS_MPI=0
The usage can be as simple as:
@benchmark
def function_to_time():
# Your computation
The result will print out to the standard output.
For fine-grained time measurements, pylops_mpi.utils.mark
can be inserted in the code region of benchmarked functions:
@benchmark
def funtion_to_time():
# You computation that you may want to ignore it in benchmark
mark("Begin Region")
# You computation
mark("Finish Region")
You can also nest benchmarked functions to track execution times across layers of function calls with the output being correctly formatted. Additionally, the result can also be exported to the text file. For completed and runnable examples, visit Benchmark Utility in PyLops-MPI