<s> import ctypes , os <EOL> import ctypes . util <EOL> CLOCK_REALTIME = <NUM_LIT:0> <EOL> CLOCK_MONOTONIC = <NUM_LIT:4> <EOL> CLOCK_UPTIME = <NUM_LIT:5> <EOL> CLOCK_UPTIME_PRECISE = <NUM_LIT:7> <EOL> CLOCK_UPTIME_FAST = <NUM_LIT:8> <EOL> class timespec ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ctypes . c_long ) , <EOL> ( '<STR_LIT>' , ctypes . c_long ) <EOL> ] <EOL> def find_lib ( libname , paths ) : <EOL> spaths = [ '<STR_LIT>' % ( path , libname ) for path in paths ] <EOL> for path in spaths : <EOL> if os . path . islink ( path ) : <EOL> libcname = os . readlink ( path ) <EOL> return ( libcname ) <EOL> elif os . path . isfile ( path ) : <EOL> for line in file ( path , '<STR_LIT:r>' ) . readlines ( ) : <EOL> parts = line . split ( '<STR_LIT:U+0020>' ) <EOL> if parts [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> continue <EOL> libcname = parts [ <NUM_LIT:2> ] <EOL> return ( libcname ) <EOL> return ctypes . util . find_library ( libname ) <EOL> def find_symbol ( symname , lnames , paths ) : <EOL> for lname in lnames : <EOL> lib = find_lib ( lname , paths ) <EOL> if lib == None : <EOL> continue <EOL> try : <EOL> llib = ctypes . CDLL ( lib , use_errno = True ) <EOL> return llib . __getitem__ ( symname ) <EOL> except : <EOL> continue <EOL> raise Exception ( '<STR_LIT>' % ( symname , lnames , paths ) ) <EOL> clock_gettime = find_symbol ( '<STR_LIT>' , ( '<STR_LIT:c>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> clock_gettime . argtypes = [ ctypes . c_int , ctypes . POINTER ( timespec ) ] <EOL> def clock_getdtime ( type ) : <EOL> t = timespec ( ) <EOL> if clock_gettime ( type , ctypes . pointer ( t ) ) != <NUM_LIT:0> : <EOL> errno_ = ctypes . get_errno ( ) <EOL> raise OSError ( errno_ , os . strerror ( errno_ ) ) <EOL> return float ( t . tv_sec ) + float ( t . tv_nsec * <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print '<STR_LIT>' % ( clock_getdtime ( CLOCK_REALTIME ) , ) <EOL> print '<STR_LIT>' % ( clock_getdtime ( CLOCK_REALTIME ) - clock_getdtime ( CLOCK_UPTIME ) , ) <EOL> print '<STR_LIT>' % ( clock_getdtime ( CLOCK_REALTIME ) - clock_getdtime ( CLOCK_UPTIME_PRECISE ) , ) <EOL> print '<STR_LIT>' % ( clock_getdtime ( CLOCK_REALTIME ) - clock_getdtime ( CLOCK_UPTIME_FAST ) , ) <EOL> print '<STR_LIT>' % ( clock_getdtime ( CLOCK_REALTIME ) - clock_getdtime ( CLOCK_MONOTONIC ) , ) </s>
