Learn Before
Code
Code Example for Timeit Module
The code snippet passed into the timeit module are usually passed in as either a string or as a function.
Command-line:
python -m timeit 'print("Hello World")'
Python Interface:
>>> import timeit >>> timeit.timeit('print("Hello World")')
Inside of a .py file:
import timeit print(timeit.timeit('print("Hello World")'))
or
import timeit def f(): print("Hello World") print(timeit.timeit(stmt=f))
0
1
Updated 2021-02-27
Tags
Python Programming Language
Data Science