Open In App

Python time.thread_time_ns() Function

Last Updated : 05 Nov, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Python time.thread_time_ns() function is used to return the value of the sum of the system and user CPU time of the current thread. It is similar to time.thread_time() function. The difference is thread_time() function return the seconds of the CPU(Computer time) but  thread_time_ns() function return the nano-seconds of the CPU(Computer time)

Syntax:

time.thread_time_ns()

Return:

nanoseconds of the computer time

Example 1: Python program that uses thread_time_ns() function

Python3
# import time module
import time

# thread_time_ns() demo
print(time.thread_time_ns())

Output:

3633875824

Example 2: Python program that demonstrates thread_time_ns() function by sleeping some seconds

Python3
# import time module
import time

# thread_time_ns() demo
print(time.thread_time_ns())

# sleep for 10 seconds
time.sleep(10)

# thread_time_ns() demo
print(time.thread_time_ns())

# sleep for 2 seconds
time.sleep(2)

# thread_time_ns() demo
print(time.thread_time_ns())
# sleep for 2 seconds
time.sleep(2)

# thread_time_ns() demo
print(time.thread_time_ns())

Output:

3616352715
3616782418
3617173584
3617551725

Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy