How would you create a decorator to measure the execution time of a function?
- By adding timestamps manually at the beginning and end of the function.
- By using the @timer decorator.
- By wrapping the function with timeit module functions.
- Python does not support measuring execution time with decorators.
You can create a decorator to measure execution time by adding timestamps manually at the start and end of the function, then calculating the time elapsed. This allows you to track how long a function takes to execute.
Loading...
Related Quiz
- The csv module's _______ class can be used to read rows from a CSV file as dictionaries.
- How can you ensure that your optimizations do not introduce errors into a Python program?
- What is the correct sequence of blocks in a conditional statement that uses all three components: if, elif, and else?
- You're working with a dictionary where keys are country names and values are their capitals. You want to invert this dictionary. What potential issue might you encounter?
- What keyword is used in Python to make a decision?