thevkrant / code_countdown_timer

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:Python 100.0%