https://stackoverflow.com/questions/1938048/high-precision-clock-in-python
Python 3.8 time.time() Precision on AMD Ryzen 7 3700X 8 cores 16 threads CPU on Ubuntu 20.04.2 LTS
Test 1 time.time()
import time
lis = [time.time() for _ in range(1000)]
for index, x in enumerate(lis):
print(str(index).zfill(3), str('%.15f'%x)) # milli micro nano pico femto
From below result, within the same micro second, the nano second differs by 200-300ns.
A rough description is that Python's time.time() can make timestamps in 200-300ns.
000 1627032470.455012798309326
001 1627032470.455013036727905
002 1627032470.455013036727905
003 1627032470.455013036727905
004 1627032470.455013275146484
005 1627032470.455013275146484
006 1627032470.455013275146484
007 1627032470.455013513565063
008 1627032470.455013513565063
Test 2 time.time_ns()
import time
lis = [time.time_ns() for _ in range(1000)]
for index, x in enumerate(lis):
print(str(index).zfill(3), x) # milli micro nano not pico femto
Stackoverflows says:
"For Linux and Mac precision is +- 1 microsecond or 0.001 milliseconds"
"Windows uses +- 16 milliseconds precision due to clock implementation problems due to process interrupts"
My test says that it is 100ns not 1us. 10 times higher precision.
second milli micro nano
000 1627032860 145 901 780
001 1627032860 145 902 021
002 1627032860 145 902 131
003 1627032860 145 902 231
004 1627032860 145 902 311
005 1627032860 145 902 431
006 1627032860 145 902 522
007 1627032860 145 902 592
008 1627032860 145 902 682
009 1627032860 145 902 792
010 1627032860 145 902 882
011 1627032860 145 902 962
012 1627032860 145 903 042
So, precision on Ubuntu is 100ns, meaning for every 2 consecutive execution the interval is 100ns.
沒有留言:
張貼留言