VOOZH about

URL: https://www.geeksforgeeks.org/python/python-time-monotonic-method/

⇱ Python | time.monotonic() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | time.monotonic() method

Last Updated : 8 Oct, 2021

Python time.monotonic() method is used to get the value of a monotonic clock. A monotonic clock is a clock that can not go backward.  As the reference point of the returned value of the monotonic clock is undefined, only the difference between the results of consecutive calls is valid.

Python time.monotonic() method Syntax:

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. 

Python time monotonic() example

Example 1: Use of time.monotonic() method to get the value of a monotonic clock 

Output:

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

Example 2: Use of time.monotonic() method to measure elapsed time in long-running process

Output:

At the beginning of the process
Value of the monotonic clock (in fractional seconds): 216491.25
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): 216516.875
Time elapsed during the process: 25.625
Comment
Article Tags: