def test_time(self):
time.time()
info = time.get_clock_info('time')
- self.assertEqual(info.is_monotonic, False)
+ self.assertEqual(info.monotonic, False)
if sys.platform != 'win32':
- self.assertEqual(info.is_adjusted, True)
+ self.assertEqual(info.adjusted, True)
def test_clock(self):
time.clock()
info = time.get_clock_info('clock')
- self.assertEqual(info.is_monotonic, True)
- self.assertEqual(info.is_adjusted, False)
+ self.assertEqual(info.monotonic, True)
+ self.assertEqual(info.adjusted, False)
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()')
self.assertAlmostEqual(dt, 0.1, delta=0.2)
info = time.get_clock_info('monotonic')
- self.assertEqual(info.is_monotonic, True)
+ self.assertEqual(info.monotonic, True)
if sys.platform == 'linux':
- self.assertEqual(info.is_adjusted, True)
+ self.assertEqual(info.adjusted, True)
else:
- self.assertEqual(info.is_adjusted, False)
+ self.assertEqual(info.adjusted, False)
def test_perf_counter(self):
time.perf_counter()
self.assertLess(stop - start, 0.01)
info = time.get_clock_info('process_time')
- self.assertEqual(info.is_monotonic, True)
- self.assertEqual(info.is_adjusted, False)
+ self.assertEqual(info.monotonic, True)
+ self.assertEqual(info.adjusted, False)
@unittest.skipUnless(hasattr(time, 'monotonic'),
'need time.monotonic')
#self.assertIsInstance(info, dict)
self.assertIsInstance(info.implementation, str)
self.assertNotEqual(info.implementation, '')
- self.assertIsInstance(info.is_monotonic, bool)
+ self.assertIsInstance(info.monotonic, bool)
self.assertIsInstance(info.resolution, float)
# 0.0 < resolution <= 1.0
self.assertGreater(info.resolution, 0.0)
self.assertLessEqual(info.resolution, 1.0)
- self.assertIsInstance(info.is_adjusted, bool)
+ self.assertIsInstance(info.adjusted, bool)
self.assertRaises(ValueError, time.get_clock_info, 'xxx')
if (info) {
info->implementation = "clock()";
info->resolution = 1.0 / (double)CLOCKS_PER_SEC;
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
}
return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC);
}
if (info) {
info->implementation = "QueryPerformanceCounter()";
info->resolution = 1.0 / (double)cpu_frequency;
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
}
*result = PyFloat_FromDouble(diff / (double)cpu_frequency);
return 0;
info->implementation = "GetTickCount64()";
else
info->implementation = "GetTickCount()";
- info->is_monotonic = 1;
+ info->monotonic = 1;
ok = GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
&isTimeAdjustmentDisabled);
if (!ok) {
return NULL;
}
info->resolution = timeIncrement * 1e-7;
- info->is_adjusted = 0;
+ info->adjusted = 0;
}
return PyFloat_FromDouble(result);
if (info) {
info->implementation = "mach_absolute_time()";
info->resolution = (double)timebase.numer / timebase.denom * 1e-9;
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
}
return PyFloat_FromDouble(secs);
if (info) {
struct timespec res;
- info->is_monotonic = 1;
+ info->monotonic = 1;
info->implementation = function;
#if (defined(linux) || defined(__linux) || defined(__linux__)) \
&& !defined(CLOCK_HIGHRES)
/* CLOCK_MONOTONIC is adjusted on Linux */
- info->is_adjusted = 1;
+ info->adjusted = 1;
#else
- info->is_adjusted = 0;
+ info->adjusted = 0;
#endif
if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
if (info) {
info->implementation = "GetProcessTimes()";
info->resolution = 1e-7;
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
}
return PyFloat_FromDouble(total * 1e-7);
#else
if (info) {
struct timespec res;
info->implementation = function;
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else
total += ru.ru_stime.tv_sec + ru.ru_stime.tv_usec * 1e-6;
if (info) {
info->implementation = "getrusage(RUSAGE_SELF)";
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
info->resolution = 1e-6;
}
return PyFloat_FromDouble(total);
total += (double)t.tms_stime / ticks_per_second;
if (info) {
info->implementation = "times()";
- info->is_monotonic = 1;
- info->is_adjusted = 0;
+ info->monotonic = 1;
+ info->adjusted = 0;
info->resolution = 1.0 / ticks_per_second;
}
return PyFloat_FromDouble(total);
static PyStructSequence_Field ClockInfo_fields[] = {
{"implementation", "name of the underlying C function "
"used to get the clock value"},
- {"is_monotonic", "True if the clock cannot go backward, False otherwise"},
- {"is_adjusted", "True if the clock can be adjusted "
+ {"monotonic", "True if the clock cannot go backward, False otherwise"},
+ {"adjusted", "True if the clock can be adjusted "
"(e.g. by a NTP daemon), False otherwise"},
{"resolution", "resolution of the clock in seconds"},
{NULL, NULL}
#ifdef Py_DEBUG
info.implementation = NULL;
- info.is_monotonic = -1;
- info.is_adjusted = -1;
+ info.monotonic = -1;
+ info.adjusted = -1;
info.resolution = -1.0;
#else
info.implementation = "";
- info.is_monotonic = 0;
- info.is_adjusted = 0;
+ info.monotonic = 0;
+ info.adjusted = 0;
info.resolution = 1.0;
#endif
goto error;
PyStructSequence_SET_ITEM(result, 0, obj);
- assert(info.is_monotonic != -1);
- obj = PyBool_FromLong(info.is_monotonic);
+ assert(info.monotonic != -1);
+ obj = PyBool_FromLong(info.monotonic);
if (obj == NULL)
goto error;
PyStructSequence_SET_ITEM(result, 1, obj);
- assert(info.is_adjusted != -1);
- obj = PyBool_FromLong(info.is_adjusted);
+ assert(info.adjusted != -1);
+ obj = PyBool_FromLong(info.adjusted);
if (obj == NULL)
goto error;
PyStructSequence_SET_ITEM(result, 2, obj);
if (info) {
struct timespec res;
info->implementation = "clock_gettime(CLOCK_REALTIME)";
- info->is_monotonic = 0;
- info->is_adjusted = 1;
+ info->monotonic = 0;
+ info->adjusted = 1;
if (clock_getres(CLOCK_REALTIME, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else