Python Tip of the Day: Benchmark Code with timeit Module
Benchmark Code with timeit
Module
Author: Jeremy Morgan
Published: November 9, 2024
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.
Curious about how fast your code runs? timeit
lets you measure execution time easily.
# Benchmark sum of numbers
import timeit
execution_time = timeit.timeit('sum(range(1000))', number=10000)
print(f"Execution time: {execution_time} seconds")
The Python Tip of the Day is a daily series published in the month of November. The tips are designed to help you become a better Python programmer. I post tips like this and more every single day on X. Let’s connect!
I wrote a book! Check out A Quick Guide to Coding with AI.
Become a super programmer!
Learn how to use Generative AI coding tools as a force multiplier for your career.