Monday, December 22, 2025
HomeLanguagesPython time.thread_time_ns() Function

Python time.thread_time_ns() Function

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
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS