@@ -45,6 +45,31 @@ def utc_time(self):
45
45
return ClockTime (seconds , nanoseconds * 1000 )
46
46
47
47
48
+ class PEP564Clock (Clock ):
49
+ """ Clock implementation based on the PEP564 additions to Python 3.7.
50
+ This clock is guaranteed nanosecond precision.
51
+ """
52
+
53
+ @classmethod
54
+ def precision (cls ):
55
+ return 9
56
+
57
+ @classmethod
58
+ def available (cls ):
59
+ try :
60
+ from time import time_ns
61
+ except ImportError :
62
+ return False
63
+ else :
64
+ return True
65
+
66
+ def utc_time (self ):
67
+ from time import time_ns
68
+ t = time_ns ()
69
+ seconds , nanoseconds = divmod (t , 1000000000 )
70
+ return ClockTime (seconds , nanoseconds )
71
+
72
+
48
73
class LibCClock (Clock ):
49
74
""" Clock implementation that works only on platforms that provide
50
75
libc. This clock is guaranteed nanosecond precision.
@@ -79,28 +104,3 @@ def utc_time(self):
79
104
return ClockTime (ts .seconds , ts .nanoseconds )
80
105
else :
81
106
raise RuntimeError ("clock_gettime failed with status %d" % status )
82
-
83
-
84
- class PEP564Clock (Clock ):
85
- """ Clock implementation based on the PEP564 additions to Python 3.7.
86
- This clock is guaranteed nanosecond precision.
87
- """
88
-
89
- @classmethod
90
- def precision (cls ):
91
- return 9
92
-
93
- @classmethod
94
- def available (cls ):
95
- try :
96
- from time import time_ns
97
- except ImportError :
98
- return False
99
- else :
100
- return True
101
-
102
- def utc_time (self ):
103
- from time import time_ns
104
- t = time_ns ()
105
- seconds , nanoseconds = divmod (t , 1000000000 )
106
- return ClockTime (seconds , nanoseconds )
0 commit comments