We can make use of the %time magic command in a Cell of a Jupyter Notebook to measure the execution time of a Python program.
Let us take a look at a few examples.
Example 1: A single Statement in a Cell
%time print(30*4039*3929)
476076930
CPU times: user 199 µs, sys: 189 µs, total: 388 µs
Wall time: 368 µs

Example 2: Execution Time of a Function Call
def func():
sum = 293*19839*29
print(sum)
We have the function in one cell and we call it from another.
%time func()
168571983
CPU times: user 36 µs, sys: 4 µs, total: 40 µs
Wall time: 42.9 µs

This works on Google Colab Notebooks as well.

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- Jupyter: Safari Cant Connect to the Server localhost:8888/tree - Python
- What version of windows do I have? - Microsoft
- Simple Crossword Puzzle example using Pure HTML, CSS and JavaScript - Html
- How to install AWS Toolkit for Visual Studio Code - AWS
- Emulator: Warning: restoring GLES1 context from snapshot. App may need reloading. - Android-Studio
- How to comment code in Python - Python
- Where are Notepad++ macros stored? - NotepadPlusPlus
- How to display Line Number in Eclipse IDE - Eclipse