Search⌘ K
AI Features

Use a decorator

Explore how to write a custom timing decorator and create a timing context manager in Python. Understand how to measure function run times effectively, useful for benchmarking slow-running tasks such as database queries or network requests.

We'll cover the following...

Writing our own timer is a lot of fun too, although it may not be as accurate as just using timeit depending on the use case. Regardless, we’re going to write our own custom function timing decorator! ...