6
from cpython cimport time as ctime
9
cdef bint IS_PYPY = hasattr(sys, 'pypy_version_info')
14
>>> tic1, tic2, tic3 = test_time()
15
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
17
>>> tic1 <= tic2 or (tic1, tic2)
19
>>> tic2 <= tic3 or (tic2, tic3)
22
# check that C-API matches Py-API to within call-time tolerance
27
return tic1, tic2, tic3
32
>>> tic1, tic2, tic3 = test_time_ns()
33
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
35
>>> tic1 <= tic2 or (tic1, tic2)
37
>>> tic2 <= tic3 or (tic2, tic3)
40
# check that C-API matches Py-API to within call-time tolerance
42
tic2 = ctime.time_ns()
45
return tic1, tic2, tic3
48
def test_perf_counter():
50
>>> tic1, tic2, tic3 = test_perf_counter()
51
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
53
>>> tic1 <= tic2 or (tic1, tic2)
55
>>> tic2 <= tic3 or (tic2, tic3)
58
# check that C-API matches Py-API to within call-time tolerance
59
tic1 = time.perf_counter() if not IS_PYPY else ctime.perf_counter()
60
tic2 = ctime.perf_counter()
61
tic3 = time.perf_counter() if not IS_PYPY else ctime.perf_counter()
63
return tic1, tic2, tic3
66
def test_perf_counter_ns():
68
>>> tic1, tic2, tic3 = test_perf_counter_ns()
69
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
71
>>> tic1 <= tic2 or (tic1, tic2)
73
>>> tic2 <= tic3 or (tic2, tic3)
76
# check that C-API matches Py-API to within call-time tolerance
77
tic1 = time.perf_counter_ns() if not IS_PYPY else ctime.perf_counter_ns()
78
tic2 = ctime.perf_counter_ns()
79
tic3 = time.perf_counter_ns() if not IS_PYPY else ctime.perf_counter_ns()
81
return tic1, tic2, tic3
86
>>> tic1, tic2, tic3 = test_monotonic()
87
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
89
>>> tic1 <= tic2 or (tic1, tic2)
91
>>> tic2 <= tic3 or (tic2, tic3)
94
# check that C-API matches Py-API to within call-time tolerance
95
tic1 = time.monotonic() if not IS_PYPY else ctime.monotonic()
96
tic2 = ctime.monotonic()
97
tic3 = time.monotonic() if not IS_PYPY else ctime.monotonic()
99
return tic1, tic2, tic3
102
def test_monotonic_ns():
104
>>> tic1, tic2, tic3 = test_monotonic_ns()
105
>>> tic1 <= tic3 or (tic1, tic3) # sanity check
107
>>> tic1 <= tic2 or (tic1, tic2)
109
>>> tic2 <= tic3 or (tic2, tic3)
112
# check that C-API matches Py-API to within call-time tolerance
113
tic1 = time.monotonic_ns() if not IS_PYPY else ctime.monotonic_ns()
114
tic2 = ctime.monotonic_ns()
115
tic3 = time.monotonic_ns() if not IS_PYPY else ctime.monotonic_ns()
117
return tic1, tic2, tic3
122
>>> ltp, ltc = test_localtime()
123
>>> ltp.tm_year == ltc['tm_year'] or (ltp.tm_year, ltc['tm_year'])
125
>>> ltp.tm_mon == ltc['tm_mon'] or (ltp.tm_mon, ltc['tm_mon'])
127
>>> ltp.tm_mday == ltc['tm_mday'] or (ltp.tm_mday, ltc['tm_mday'])
129
>>> ltp.tm_hour == ltc['tm_hour'] or (ltp.tm_hour, ltc['tm_hour'])
131
>>> ltp.tm_min == ltc['tm_min'] or (ltp.tm_min, ltc['tm_min'])
133
>>> ltp.tm_sec == ltc['tm_sec'] or (ltp.tm_sec, ltc['tm_sec'])
135
>>> ltp.tm_wday == ltc['tm_wday'] or (ltp.tm_wday, ltc['tm_wday'])
137
>>> ltp.tm_yday == ltc['tm_yday'] or (ltp.tm_yday, ltc['tm_yday'])
139
>>> ltp.tm_isdst == ltc['tm_isdst'] or (ltp.tm_isdst, ltc['tm_isdst'])
142
ltp = time.localtime()
143
ltc = ctime.localtime()
146
while ltp.tm_sec != ltc.tm_sec:
147
# If the time.localtime call is just before the end of a second and the
148
# ctime.localtime call is just after the beginning of the next second,
149
# re-call. This should not occur twice in a row.
151
ltp = time.localtime()
152
ltc = ctime.localtime()