from __future__ import division from ctypes import * dll = windll.kernel32 class ZTimer: def __init__(self): self.startcount = c_longlong() self.endcount = c_longlong() self.frequency = c_longlong() self.counts = 0 self.seconds = 0 self.millis = 0 self.micros = 0 def start(self): dll.QueryPerformanceCounter(byref(self.startcount)) def stop(self): dll.QueryPerformanceCounter(byref(self.endcount)) self.counts = self.endcount.value - self.startcount.value dll.QueryPerformanceFrequency(byref(self.frequency)) self.seconds = self.counts / self.frequency.value self.millis = self.seconds*1000 self.micros = self.millis*1000 if __name__=='__main__': t = ZTimer() t.start() t.stop() print t.counts print t.seconds print t.millis print t.micros