[Pythonmac-SIG] Microseconds.py
Just van Rossum
just@letterror.com
Tue, 19 May 1998 21:46:47 +0200
I just learned in comp.sys.mac.programmer.whatever that there exists a
toolbox function called Microseconds(). Apparently it is not really precise
up to the Microsecond, but still a whole lot more precise than TickCount().
Thanks to Jack's wonderful calldll module, I was able to interface it in a
matter of minutes (but won't run on 68k ;-).
This might be useful for better profiling, where TickCount is really
somewhat too course.
Just
# Microseconds.py
import calldll
import struct
_InterfaceLib = calldll.getlibrary('InterfaceLib')
_Microseconds = calldll.newcall(_InterfaceLib.Microseconds,
'None', 'InString')
def Microseconds():
"""erm, don't try this at home..."""
a = '\0' * 8
_Microseconds(a)
h, l = struct.unpack('LL', a)
return float((h << 32) | l)
def _test():
import Evt
while 1:
print Microseconds() / 1000000.0,
print Evt.TickCount() / 60.0
if __name__ == "__main__":
_test()