qi clock API

Introduction

Libqi provides C++ types to model clocks, time points and durations. See qi clocks for an overview of the clocks.

The functions to get the current time of these clocks are also available in python. They return an integer number of nanoseconds.

You can use qi.systemClockNow() as a substitute for python’s time.time() :


            
             import qi
import time

fmt = "%a, %d %b %Y %H:%M:%S +0000"
t_sec = time.time() # floating point
print("current local time is: " + time.ctime(t_sec))

t_nsec = qi.systemClockNow() # integer
t_sec = t_nsec * 1e-9 # floating point
print("current local time is: " + time.ctime(t_sec))

            
           

qi.clockNow() is mostly used for system-wide timestamps. Sometimes, you may need the timestamp as a pair of integers, counting seconds and microseconds, respectively. This can be done with:


            
             import qi

t_usec = qi.clockNow()/1000
timestamp = [t_usec/1000000, t_usec % 1000000]

            
           

qi.steadyClockNow() is useful when one needs to measure durations while being robust to system clock changes, as in


            
             import qi
import time

t0_msec = qi.steadyClockNow()/1000000
time.sleep(0.5)
t1_msec = qi.steadyClockNow()/1000000
print("I slept during " + str(t1_msec - t0_msec) + " milliseconds")

            
           

Reference

qi. systemClockNow ( ) → Int
Returns: current timestamp on qi::SystemClock, as a number of nanoseconds
qi. clockNow ( ) → Int
Returns: current timestamp on qi::Clock, as a number of nanoseconds
qi. steadyClockNow ( ) → Int
Returns: current timestamp on qi::SteadyClock, as a number of nanoseconds