Love this library @mbdevpl . Was just playing around with some benchmarks for an article I plan to write on Python multiprocessing + numpy arrays, and I ran into some unintuitive behaviour:
for _ in _TIME.measure_many("baseline", samples=n_frames):
baseline_benchmark(np_arr)
for _ in _TIME.measure_many("mp_queue", samples=n_frames):
mp_queue_benchmark(np_arr, mp_queue)
for _ in _TIME.measure_many("queue_module", samples=n_frames):
queue_module_benchmark(np_arr, queue_module)
timings.append(get_timings("baseline", n_frames))
timings.append(get_timings("mp_queue", n_frames))
timings.append(get_timings("queue_module", n_frames))
This code works. But rearranging the same code to:
for _ in _TIME.measure_many("baseline", samples=n_frames):
baseline_benchmark(np_arr)
timings.append(get_timings("baseline", n_frames))
for _ in _TIME.measure_many("mp_queue", samples=n_frames):
mp_queue_benchmark(np_arr, mp_queue)
timings.append(get_timings("mp_queue", n_frames))
for _ in _TIME.measure_many("queue_module", samples=n_frames):
queue_module_benchmark(np_arr, queue_module)
timings.append(get_timings("queue_module", n_frames))
Returns
╰─❯ python array_benchmark/queue_benchmarking/queues.py
baseline: time: = 0.0008 +/- 0.0001 or FPS = 121740.87059304002
Traceback (most recent call last):
File "array_benchmark/queue_benchmarking/queues.py", line 100, in <module>
DF = benchmark_queues()
File "array_benchmark/queue_benchmarking/queues.py", line 83, in benchmark_queues
timings.append(get_timings("mp_queue", n_frames))
File "array_benchmark/queue_benchmarking/queues.py", line 61, in get_timings
mean = f"{_TIME.summary[groupname]['mean']:.4f}"
KeyError: 'mp_queue'
Whereby I am using this function.
def get_timings(groupname, n_frames):
""" Get a dictionary of the mean/std and FPS of the timing group.
:param str groupname: name of the timing group
:param int n_frames: number of timing repeats
:return: mean/std and FPS of the timing group as a dictionary
:rtype: dict
"""
mean = f"{_TIME.summary[groupname]['mean']:.4f}"
stddev = f"{_TIME.summary[groupname]['stddev']:.4f}"
fps = f"{n_frames / _TIME.summary[groupname]['mean']}"
print(f"{groupname}: time: = {mean} +/- "
f"{stddev}"
f" or FPS = {fps}")
return {"groupname": groupname, "mean": mean, "stddev": stddev, "fps": fps}
Not sure if it is a bug or expected behaviour, but it seems that a requirement is that all summary metrics are calculated after all timings are complete, is that the case, if so might best to add to the docs.
Love this library @mbdevpl . Was just playing around with some benchmarks for an article I plan to write on Python multiprocessing + numpy arrays, and I ran into some unintuitive behaviour:
This code works. But rearranging the same code to:
Returns
Whereby I am using this function.
Not sure if it is a bug or expected behaviour, but it seems that a requirement is that all summary metrics are calculated after all timings are complete, is that the case, if so might best to add to the docs.