The time module

The time module allows the user to directly get the time, in seconds, since 1970 (See: https://docs.python.org/3/library/time.html). This means that we can subtract the time before from time after to see how long it has been, namely how long it took the user to finish the typing test. From there, it is as easy as printing the result. You can round the time using int to get a purely seconds result without milliseconds.

The code

# Import the time library
import time

# Calculate the start time
start = time.time()

# Code here

# Calculate the end time and time taken
end = time.time()
length = end - start

# Show the results : this can be altered however you like
print("It took", length, "seconds!")
Answer from Larry the Llama on Stack Overflow
🌐
Real Python
realpython.com › python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - Using a timer involves recording timestamps before and after a specific code block and calculating the time difference to determine how long your code took to run. [ ... ] ## Read the full article at https://realpython.com/python-timer/ » * * *
🌐
LearnDataSci
learndatasci.com › solutions › python-timer
Create a Timer in Python: Elapsed Time, Decorators, and more – LearnDataSci
One advantage of using the @contextmanager decorator to define our timer is that we can use the timer both using the with statement and as a function decorator, like in the last example. If we wanted to time a certain operation once, we could call in timer() using a with statement.
🌐
Udacity
udacity.com › blog › 2021 › 09 › create-a-timer-in-python-step-by-step-guide.html
Create a Timer in Python: Step-by-Step Guide | Udacity
September 27, 2022 - Within the loop, we use the timedelta() function to calculate the time left on the timer. The program prints the time left in hours:minutes:seconds format for the user to see. Immediately after, the program pauses for one second, reduces total_seconds by one second, and repeats the while loop. The loop continues until total_seconds reaches zero, at which point the program leaves the while loop and prints “Bzzzt! The countdown is at zero seconds!” · You can use Python to measure the time it takes for a program to finish execution.
🌐
GitHub
github.com › realpython › codetiming
GitHub - realpython/codetiming: A flexible, customizable timer for your Python code · GitHub
A flexible, customizable timer for your Python code - realpython/codetiming
Starred by 310 users
Forked by 40 users
Languages   Python
🌐
Python
docs.python.org › 3 › library › timeit.html
timeit — Measure execution time of small code snippets
Time number executions of the main statement. This executes the setup statement once, and then returns the time it takes to execute the main statement a number of times. The default timer returns seconds as a float.
🌐
Medium
medium.com › @andrewdass › how-to-make-a-timer-in-python-76cd679c5725
How to make a Timer in Python. Overview | by Andrew Dass | Medium
December 30, 2023 - All the snippets of code shown above is implemented within the timer function: #!/usr/bin/env python3 # Completed Script import datetime, time def timer(): while True: try: insert_year = int(input("Enter the year number: ")) if insert_year >= 0: break except ValueError: print("Not a real year number.
Find elsewhere
🌐
Medium
k3no.medium.com › taming-time-in-python-65a625ade93f
Taming Time in Python. Timers, stopwatches, threading and… | by Keno Leon | Medium
November 10, 2021 - The result from running the previous script should be:Hello from : TIMER THREE Hello from : TIMER ONE Hello from : TIMER TWOA timer is made by defining the interval in seconds to wait before running the function/callback, the only weird thing ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-create-a-countdown-timer-using-python
How To Create a Countdown Timer Using Python? - GeeksforGeeks
May 9, 2025 - import time def countdown(t): while t: mins, secs = divmod(t, 60) timer = '{:02d}:{:02d}'.format(mins, secs) print(timer, end='\r') # Overwrite the line each second time.sleep(1) t -= 1 print("Fire in the hole!!") t = input("Enter the time in seconds: ") countdown(int(t))
🌐
Educative
educative.io › answers › how-to-create-a-timer-in-python
How to create a timer in Python
Countdown timers: These timers are established with a designated time duration that diminishes until the timer reaches zero. They are commonly used to create time limits, implement timeouts, schedule reminders, or trigger actions at specific points in time. Python offers the option to construct timers from scratch using either the threading module or the time module.
🌐
Jakob-bagterp
jakob-bagterp.github.io › timer-for-python
The Easy Way to Start, Stop and Measure Time - Timer for Python ⏳
Timer for Python is a lightweight package that measures performance of your code. Get started in minutes with code examples for beginners and advanced users.
🌐
Built In
builtin.com › articles › timing-functions-python
Timing Functions in Python: A Guide | Built In
The timeit module provides a simple way to time the execution of small bits of Python code. It can be used to time a single function by wrapping it in a timeit.Timer object and calling the timeit() method.
🌐
Reddit
reddit.com › r/learnpython › how to make a timer ?
r/learnpython on Reddit: How to make a timer ?
August 14, 2024 -

Hello guys ! I’m starting with python a week ago, I don’t have all the knowledge etc…, but I’m very curious and I wish to know a method or how to make a Timer in python… like my timer start at 35min and decrease to 0 or to 0 to 35. If anybody have an idea how to do this, I'll take it !! See you ! 🐍

🌐
MicroPython
docs.micropython.org › en › latest › library › machine.Timer.html
class Timer – control hardware timers — MicroPython latest documentation
Timer class provides the ability to trigger a Python callback function after an expiry time, or periodically at a regular interval.
🌐
Python Pool
pythonpool.com › home › blog › understanding the python timer class with examples
Understanding the Python Timer Class with Examples - Python Pool
May 23, 2021 - If we want to delay the execution of a function by a certain amount of time, we can use the python timer class. start() and cancel() are two of its methods.
🌐
PyPI
pypi.org › project › timer-for-python
timer-for-python · PyPI
Lightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code. Ready to try? Learn how to install and find tutorials in the user guide.
      » pip install timer-for-python
    
Published   Feb 11, 2026
Version   0.9.9
🌐
PyPI
pypi.org › project › timer
timer
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Instructables
instructables.com › teachers › grades 3-5
Step-by-step Coding Tutorial for a Simple Timer in Python : 10 Steps - Instructables
December 28, 2023 - Step-by-step Coding Tutorial for a Simple Timer in Python: In this tutorial, we will create a simple console-based timer application using Python. The application will: 1. Prompt the user to enter a duration for the timer in minutes. 2. Convert the user's input from minutes to seconds for the ...
🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
On Windows, if secs is zero, the thread relinquishes the remainder of its time slice to any other thread that is ready to run. If there are no other threads ready to run, the function returns immediately, and the thread continues execution. On Windows 10 and newer the implementation uses a high-resolution timer which provides resolution of 100 nanoseconds.