Change language

Python | time.monotonic () method

time.monotonic() The time unit in Python is used to get the value of a monotonic clock. Monotonous clock — it is a clock that cannot move backward. 
Since there is no checkpoint for the return value of monotonic hours, only the difference between the results of successive calls is allowed.

Syntax: time.monotonic ()

Parameter: No parameter is required.

Return type: This method returns a float value which represents the value of a monotonic clock in fractional seconds.

Code # 1: Using the time.monotonic() method to get the monotonic clock value

# Python program to explain the time.monotonic () method

 
# time module import

import time

 
# Get the value
# monotonous hours using
# time.monotonic () method

value = time.monotonic ()

 
# output the value
# monotonous hours

print ( "Value of the monotonic clock (in fractional seconds):" , value)

Exit:

 Value of the monotonic clock (in fractional seconds): 2116.429736057 

Code # 2: Using the time.monotonic() method to measure the elapsed time in long process.

# Python program to explain the time.monotonic () method

 
# time module import

import time

 
# Get the value
# monotonous hours on
# start the process code>
# using the time.monotonic () method

start = time.monotonic ()

 
# print the value
# monotonous hours

print ( "At the beginning of the process " )

print ( "Value of the monotonic clock (in fractional seconds):" , start)

 

i = 0

arr = [ 0 ] * 10

while i & lt;  10 :

# Accept user input

arr [i] = int ( input ())

i = i + 1

 
# Print user input

print (arr)

 
# Get the value
# monotonous hours
# using met ode time.monotonic ()

end = time.monotonic ()

 
# output the value
# monotonous hours

print ( "At the end of the process" )

print ( "Value of the monotonic clock (in fractional seconds):" , end)

print ( "Time elapsed during the process: " , end - start) 

Exit:

 At the beginning of the process Value of the monotonic c lock (in fractional seconds): 3957.237067598 1 2 3 4 5 6 7 8 9 10 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] At the end of the process Value of the monotonic clock (in fractional seconds): 3966.407866892 Time elapsed during the process (in fractional seconds): 9.170799294000062 

Link: https://docs.python.org/3/library/time.html#time.monotonic

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method