Discover more from Daily Dose of Data Science
Don't Use time.time() To Measure Execution Time
The 𝘁𝗶𝗺𝗲() method from the time library is frequently used to measure the execution time.
However, 𝘁𝗶𝗺𝗲() is not meant for timing your code. Rather, its actual purpose is to tell the current time. This, at many times, compromises the accuracy of measuring the exact run time.
The correct approach is to use 𝗽𝗲𝗿𝗳_𝗰𝗼𝘂𝗻𝘁𝗲𝗿(), which deals with relative time. Thus, it is considered the most accurate way to time your code.
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.
I like to explore, experiment and write about data science concepts and tools. You could connect with me on LinkedIn.