High resolution time measurement (Python) UserPageVisits:3433 active 80 80 DaniWeb 561 60 2013-10-23T18:11:01+00:00 https://www.daniweb.com/programming/software-development/code/465991/high-resolution-time-measurement-python

High resolution time measurement (Python)

vegaseat

Starting with Python 3.3 you now have access to a high resolution time counter (nanoseconds and better).

Gribouillis commented: very nice +14
TrustyTony commented: Good info +12
3,433 Views
About the Author

Scientist

code snippet
''' time_high_resolution_counter.py
measure elapsed time of a Python calculation
time.perf_counter() is new in Python 3.3
'''

import time

# returned value is in fractional seconds
start = time.perf_counter()

# let's time this calculation
y = 2**0.5

end = time.perf_counter()

elapsed = end - start
print("elapsed time = {:.12f} seconds".format(elapsed))

''' result (on an intel core i5 computer) ...
elapsed time = 0.000000410520 seconds
'''
ddanbe 2,724

Thanks for the info.
So this would be about 410 nanoseconds?

Correct

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.