Timeit Module

Introduction to Timeit module

This is module is used to see the time elapsed during code execution. It is useful for small code snippets only.

Unlike the time module, it avoids a number of common traps for measuring execution times.

As we have discussed generators in the previous blog in that we covered that generators are less time to consume. If you want to go through that blog, just go to this link.

Here, in this blog, we will discuss Timeit module by taking an example of how much time is generally taken by generators and list comprehension.

Syntax:   timeit.timeit(‘Python code’ , number = no._of_repititions)

Now, will look at an example -:

Checking time taken by generators using timeit

Checking time taken by list using timeit

So, this is all for the timeit module. Hope you understand the use of it.

Stay tuned for more amazing blogs. Keep learning Machine Learning with us.

 

Close Menu