How to Benchmark (Python) Code

Sebastian Witowski
9 min readNov 17, 2022

While preparing to write the “Writing Faster Python” series, the first problem I faced was:

“How do I benchmark a piece of code in an objective yet uncomplicated way?”

I could run python -m timeit <piece of code>, which is probably the simplest way of measuring how long it takes to execute some code¹. But maybe it's too simple, and I owe my readers some way of benchmarking that won't…

Sebastian Witowski

Python consultant and freelancer at switowski.com. Writes about productivity, tools, Python, and programming best practices.