Python | time.monotonic_ns() method Last Updated : 08 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.monotonic_ns() method of time module in Python is used to get the value of a monotonic clock in nanoseconds. This method is similar to time.monotonic() method which returns the monotonic clock value in fractional seconds. A monotonic clock is a clock that can not go backwards. Syntax: time.monotonic_ns() Parameter: No parameter is required. Return type: This method returns an integer value which represents the value of a monotonic clock in nanoseconds. Code #1: Use of time.monotonic_ns() method to get value of a monotonic clock in nanoseconds Python3 # Python program to explain time.monotonic_ns() method # importing time module import time # Get the value of # the monotonic clock in # fractional seconds using # time.monotonic() method value1 = time.monotonic() # Get the value of # the monotonic clock in # nanoseconds using # time.monotonic_ns() method value2 = time.monotonic_ns() # print the value of # the monotonic clock (in fractional seconds) print("Value of the monotonic clock (in fractional seconds):", value1) # print the value of # the monotonic clock (in nanoseconds) print("Value of the monotonic clock (in nanoseconds):", value2) Output:Value of the monotonic clock (in fractional seconds): 13486.679399824 Value of the monotonic clock (in nanoseconds): 13486679402777 Code #2: Use of time.monotonic_ns() method to measure elapsed time in long running process. Python3 # Python program to explain time.monotonic_ns() method # importing time module import time # Function to calculate factorial # of the given number def factorial(n): f = 1 for i in range(n, 1, -1): f = f * i return f # Get the value of the # monotonic clock in nanoseconds at the # beginning of the process # using time.monotonic_ns() method start = time.monotonic_ns() # print the value of # the monotonic clock in nanoseconds print("At the beginning of the process") print("Value of the monotonic clock (in nanoseconds):", start, "\n") # Calculate factorial of all # numbers from 0 to 9 i = 0 fact = [0] * 10; while i < 10: fact[i] = factorial(i) i = i + 1 # Print the calculated factorial for i in range(0, len(fact)): print("Factorial of % d:" % i, fact[i]) # Get the value of # monotonic clock in nanoseconds # using time.monotonic_ns() method end = time.monotonic_ns() # print the value of # the monotonic clock print("\nAt the end of the process") print("Value of the monotonic clock (in nanoseconds):", end) print("Time elapsed during the process:", end - start) Output:At the beginning of the process Value of the monotonic clock (in nanoseconds): 14671301967243 Factorial of 0: 1 Factorial of 1: 1 Factorial of 2: 2 Factorial of 3: 6 Factorial of 4: 24 Factorial of 5: 120 Factorial of 6: 720 Factorial of 7: 5040 Factorial of 8: 40320 Factorial of 9: 362880 At the end of the process Value of the monotonic clock (in nanoseconds): 14671302231487 Time elapsed during the process: 264244 Reference: https://docs.python.org/3/library/time.html#time.monotonic_ns Comment More infoAdvertise with us Next Article Python | time.monotonic_ns() method I ihritik Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads Python | time.asctime() method Python time method time.asctime() is used to convert a tuple or a time.struct_time object representing a time as returned by time.gmtime() or time.localtime() method to a string of the following form: Day Mon Date Hour:Min:Sec Year For example: Thu 08 22 10:46:56 2019Python time asctime() Syntax: ti 3 min read Python time.pthread_getcpuclockid() Function The pthread_getcpuclockid() function returns the clock id of the thread-specific CPU-time clock for the specified thread_id. The thread ids are obtained from the different threads that are running being used by that program. The thread ids can be obtained using the 'ident' field of the threading cla 2 min read Python | time.clock_getres() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.clock_getres() method of Time module is used to get the resolution or precision of the specified clock clk_id. Basically, clk_id is a integer value which represents the id o 3 min read Python | time.clock_gettime() method time.clock_gettime() method of Time module is used to get the time of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. Following are the constants available on UNIX platforms that can be used as value of clk_id parameter: clk_id clk_id constant M 3 min read Python | time.clock_gettime_ns() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.clock_gettime_ns() method of Time module is used to get the time (in nanoseconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id 3 min read Python | time.clock_settime() method time.clock_settime() method of Time module is used to set the time (in seconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. Syntax: time.clock_settime(clk_id, seconds) Parameters: clk_id: A clk_id constant or an integer value representing 1 min read Python | time.clock_settime_ns() method time.clock_settime_ns() method of Time module is used to set the time (in nanoseconds) of the specified clock clk_id. Basically, clk_id is a integer value which represents the id of the clock. This method is similar to time.clock_settime() method which is used to set time of the specified clock clk_ 2 min read Python - time.ctime() Method Python time.ctime() method converts a time in seconds since the epoch to a string in local time. This is equivalent to asctime(localtime(seconds)). Current time is returned by localtime() is used when the time tuple is not present. Syntax: time.ctime([ sec ]) Parameter: sec: number of seconds to be 2 min read Python | time.get_clock_info() method Time module in Python provides various time related functions. time.get_clock_info() method in Time module is used to get the information on the specified clock name. This method return the information as a namespace object. The name of supported clocks and the method used to read that clock value a 2 min read Python | time.gmtime() method Time module in Python provides various time-related functions. This module comes under Pythonâs standard utility modules. time.gmtime() method of Time module is used to convert a time expressed in seconds since the epoch to a time.struct_time object in UTC in which tm_isdst attribute is always 0. To 3 min read Like