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 - >>> from timer import Timer >>> with Timer(): ... for num in range(-3, 3): ... print(f"1 / {num} = {1 / num:.3f}") ... 1 / -3 = -0.333 1 / -2 = -0.500 1 / -1 = -1.000 Elapsed time: 0.0001 seconds Traceback (most recent call last): File "<stdin>", line 3, in <module> ZeroDivisionError: division by zero · Note that Timer prints out the elapsed time, even though the code crashed. It’s possible to inspect and suppress errors in .__exit__(). See the documentation for more information. Now you’ll learn how to use the Timer context manager to time the download of Real Python tutorials.
🌐
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
🌐
LearnDataSci
learndatasci.com › solutions › python-timer
Create a Timer in Python: Elapsed Time, Decorators, and more – LearnDataSci
Since we have roughly established how to calculate the elapsed time, we can refine our code a little. Python's time module offers us alternatives to the time() function, all reporting the time in seconds but in different ways.
🌐
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 - We’ll then use these modules to build a stopwatch and a countdown timer, and show you how to measure a Python program’s execution time.
🌐
Python
docs.python.org › 3 › library › timeit.html
timeit — Measure execution time of small code snippets
This module provides a simple way to time small bits of Python code. It has both a Command-Line Interface as well as a callable one. It avoids a number of common traps for measuring execution times.
🌐
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
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › timer-objects-python
Timer Objects in Python - GeeksforGeeks
June 28, 2017 - # Program to demonstrate # timer objects in python import threading def gfg(): print("GeeksforGeeks\n") timer = threading.Timer(2.0, gfg) timer.start() print("Exit\n") Output:
🌐
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.
🌐
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
🌐
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 - There are different types of timer implementations in python according to user needs, namely, python timer function (to check script execution time), python threading timer (to check the time taken by a thread to finish), python countdown timer (create a countdown timer) and basic python time module (to help with other activities).
🌐
Educative
educative.io › answers › how-to-create-a-timer-in-python
How to create a timer in Python
Python offers the option to construct timers from scratch using either the threading module or the time module.
🌐
iO Flood
ioflood.com › blog › python-timer
Python Timer Usage Guide
February 7, 2024 - The timeit module provides a simple way to time small bits of Python code. It has both a command-line interface and a callable one. It avoids a number of common traps for measuring execution times.
🌐
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 ...
🌐
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.
🌐
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 ! 🐍

🌐
GeeksforGeeks
geeksforgeeks.org › how-to-create-a-countdown-timer-using-python
How To Create a Countdown Timer Using Python? - GeeksforGeeks
May 9, 2025 - In this article, we will see how to create a countdown timer using Python. The code will take input from the user regarding the length of the countdown in seconds. After that, a countdown will begin on the screen of the format 'minutes: seconds'. We will use the time module here.
🌐
Nickmccullum
nickmccullum.com › python-timer-functions-performance-measurement
How to Use Python Timer Functions for Performance Measurement | Nick McCullum
October 15, 2020 - In these instances, we can use python timers to identify the performance impact of the code and make the necessary modifications. Here are some predefined functions in built-in time module.