How to use clock_settime method in pytest-benchmark

Best Python code snippet using pytest-benchmark

clock.py

Source:clock.py Github

copy

Full Screen

1#!/usr/bin/env python2# Python interface into the posix clock functions3# clock_gettime(), clock_settime()4#5# Motivation is to get access to CLOCK_MONOTONIC, so flight code can not care6# about jumps in system time (in which case CLOCK_REALTIME and python's7# datetime jump).8import ctypes9import os10CLOCK_REALTIME = 011CLOCK_MONOTONIC = 112CLOCK_PROCESS_CPUTIME_ID = 213CLOCK_THREAD_CPUTIME_ID = 314CLOCK_MONOTONIC_RAW = 415CLOCK_REALTIME_COARSE = 516CLOCK_MONOTONIC_COARSE = 617CLOCK_BOOTTIME = 718CLOCK_REALTIME_ALARM = 819CLOCK_BOOTTIME_ALARM = 920class timespec(ctypes.Structure):21 _fields_ = [22 ("tv_sec", ctypes.c_long),23 ("tv_nsec", ctypes.c_long)24 ]25librt = ctypes.CDLL('librt.so.1', use_errno=True)26clock_gettime = librt.clock_gettime27clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]28clock_settime = librt.clock_settime29clock_settime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]30def gettime(clock_id):31 t = timespec()32 if clock_gettime(clock_id, ctypes.pointer(t)) != 0:33 errno_ = ctypes.get_errno()34 raise OSError(errno_, os.strerror(errno_))35 return t36def gettime_us(clock_id):37 t = gettime(clock_id)38 return long(t.tv_sec * 1000000 + (t.tv_nsec + 500) / 1000)39def settime(clock_id, t):40 if clock_settime(clock_id, ctypes.pointer(t)) != 0:41 errno_ = ctypes.get_errno()42 raise OSError(errno_, os.strerror(errno_))43def settime_us(clock_id, us):44 t = timespec(us/1000000, (us%1000000) * 1000)45 if clock_settime(clock_id, ctypes.pointer(t)) != 0:46 errno_ = ctypes.get_errno()47 raise OSError(errno_, os.strerror(errno_))48def test(do_set):49 rt = gettime(CLOCK_REALTIME)50 print "REALTIME: %10d.%09d" % (rt.tv_sec, rt.tv_nsec)51 mt = gettime(CLOCK_MONOTONIC)52 print "MONOTONIC: %10d.%09d" % (mt.tv_sec, mt.tv_nsec)53 if do_set:54 # WARNING: this sets the time to zero (1/1/1970)55 print "set time..."56 os.system("date --set=\"@0\"")57 rt = gettime(CLOCK_REALTIME)58 print "REALTIME: %10d.%09d" % (rt.tv_sec, rt.tv_nsec)59 mt = gettime(CLOCK_MONOTONIC)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful