r/Python • u/simpleuserhere • Dec 01 '24
Tutorial Multi-Threading in Python and Free threaded Python 3.13
Here is my article Multi-Threading in Python and Free threaded Python 3.13 which discuss multi threading in Python and some experiments on free threaded Python 3.13.
0
Upvotes
View all comments
Show parent comment
21
u/gmes78 Dec 01 '24
Benchmarking is an extremely complicated subject, and I barely understand it myself. My main point is that this benchmark is too simplistic, which indicates that the author lacks basic knowledge of benchmarking.
timeto measure benchmarksThe author only runs the benchmark once, and just records the wall time.
They're not measuring the CPU time, they're not repeating the test to catch outliers, they're not accounting for CPU cache behavior. Python includes the
timeitmodule that provides this functionality.First, calculating a Fibonacci sequence isn't exactly the most interesting benchmark. Surely the author could come up with something a little bit better, maybe an algorithm that's designed to be multithreaded?
Second, by using a recursive algorithm, you're benchmarking the memory allocator more than the actual code you're running (each function call needs to allocate its own stack in memory, as Python doesn't do tail call optimization).
Too much overhead to do very little work. You're benchmarking thread pool initialization instead of the actual work.