Python time.perf_counter_ns() Function
Last Updated :
05 Nov, 2021
Python time.perf_counter_ns() function gives the integer value of time in nanoseconds.
Syntax:
from time import perf_counter_ns
We can find the elapsed time by using start and stop functions. We can also find the elapsed time during the whole program by subtracting stoptime and starttime
Example 1:
Python3
from time import perf_counter_ns
n, m = map ( int , input ().split())
start = perf_counter_ns()
for i in range (n):
t = int ( input ())
if t % m = = 0 :
print (t)
stop = perf_counter_ns()
print ( "Elapsed time:" , stop, 'ns' , start, 'ns' )
print ( "Elapsed time during the whole program" ,
stop - start, 'ns' )
|
Output:
Example 2:
Python3
from time import perf_counter_ns
n, m = map ( int , input ().split())
start = perf_counter_ns()
for i in range (n):
t = int ( input ())
if t % m = = 0 :
print (t)
stop = perf_counter_ns()
print ( "Elapsed time:" , stop, 'ns' , start, 'ns' )
print ( "Elapsed time during the whole program" ,
stop - start, 'ns' )
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...