Skip to content

This Python script returns how long it takes to create a list from a range using a for loop.

License

Notifications You must be signed in to change notification settings

thevkrant/code_countdown_timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code Countdown Timer

Python tip:

There is a simple way to create a code countdown timer using the perf_counter() class from the time module. I wrote a function that demonstrates how you can use it as a performance counter for your code.

  • perf_counter() returns how long it takes to create a list from a range using a for loop.

Prerequisites

Python 3

Source Code

import time

def timer():
    list1 = []
    start = time.perf_counter()
    for i in range(10000000):
        list1.append(i**2)
    end = time.perf_counter()
    return f'Code Run time is {end - start:0.2f} seconds'

if __name__ == "__main__":
    print(timer())

Author Name

Vikrant

About

This Python script returns how long it takes to create a list from a range using a for loop.

Topics

Resources

License

Stars

Watchers

Forks

Languages