Best Python code snippet using pytest-benchmark
timing.py
Source:timing.py
...30 # From <mach/mach_time.h>31 KERN_SUCCESS = 032 libSystem = ctypes.CDLL('/usr/lib/libSystem.dylib', use_errno=True)33 mach_timebase_info = libSystem.mach_timebase_info34 class struct_mach_timebase_info(ctypes.Structure):35 _fields_ = [('numer', ctypes.c_uint32), ('denom', ctypes.c_uint32)]36 mach_timebase_info.argtypes = [ctypes.POINTER(struct_mach_timebase_info)]37 mach_ti = struct_mach_timebase_info()38 ret = mach_timebase_info(ctypes.byref(mach_ti))39 if ret != KERN_SUCCESS:40 raise Exception('Could not get mach_timebase_info, error: ' + str(ret))41 mach_absolute_time = libSystem.mach_absolute_time42 mach_absolute_time.restype = ctypes.c_uint6443 def _monotonic_time_nanos_darwin():44 return (mach_absolute_time() * mach_ti.numer) / mach_ti.denom45 monotonic_time_nanos = _monotonic_time_nanos_darwin46elif platform.system() == 'Windows':47 # From <Winbase.h>48 perf_frequency = ctypes.c_uint64()49 ctypes.windll.kernel32.QueryPerformanceFrequency(ctypes.byref(perf_frequency))50 def _monotonic_time_nanos_windows():51 perf_counter = ctypes.c_uint64()52 ctypes.windll.kernel32.QueryPerformanceCounter(ctypes.byref(perf_counter))...
_time.py
Source:_time.py
...32 mach_timebase_info = lib.mach_timebase_info33 mach_timebase_info.restype = None34 mach_timebase_info.argtypes = [ctypes.POINTER(mach_timebase_info_t)]35 self._timebase = mach_timebase_info_t()36 mach_timebase_info(self._timebase)37 self._mach_absolute_time = lib.mach_absolute_time38 self._mach_absolute_time.restype = ctypes.c_uint6439 self._mach_absolute_time.argtypes = []40 self._start = self._mach_absolute_time()41 def monotonic(self):42 elapsed = self._mach_absolute_time() - self._start43 timestamp = elapsed * self._timebase.numerator / self._timebase.denominator44 sec, nsec = divmod(timestamp, 10 ** 9)45 return sec + nsec * (10 ** -9)46class LinuxTime(object):47 CLOCK_MONOTONIC = 148 _byref = ctypes.byref49 _strerror = os.strerror50 _get_errno = ctypes.get_errno...
mach_time.py
Source:mach_time.py
...12mach_timebase_info = CDLL(None).mach_timebase_info13mach_timebase_info.restype = c_int14mach_timebase_info.argtypes = (POINTER(mach_timebase_info_data_t),)15_info = mach_timebase_info_data_t()16mach_timebase_info(pointer(_info))17assert time.get_clock_info('monotonic').implementation == 'mach_absolute_time()'18# reconstruct value of t0 in19# https://github.com/python/cpython/blob/e42b705188271da108de42b55d9344642170aa2b/Python/pytime.c#L85520def pymonotonic_t0():21 t1 = time.monotonic()22 t2 = mach_absolute_time()23 t3 = time.monotonic()24 return t2 - int((t1+t3)/2 * 1e9 * _info.denom / _info.numer)25pymonotonic_t0 = int(np.array([pymonotonic_t0() for i in range(1000)], np.uint64).sum() / 1000 + .5)26def hostTimeToMonotonic(hostTime):27 return (hostTime - pymonotonic_t0) * _info.numer / _info.denom * 1e-928def monotonicToHostTime(monotonic):29 return int(monotonic * 1e9 * _info.denom / _info.numer) + pymonotonic_t030# partial derivatives...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!