Вот типа KTimer
| Код | Option Explicit
'ДЛЯ ПРОЦЕССОРОВ INTEL
'---------- Пример использования ----------- ' Dim cycles As Long, cpusp As Long ' cpusp = timer.CpuSpeed ' timer.StartTime
' ... здесь проверяемый код ... ' к-во тактов = timer.StopTime ' к-во микросекунд = timer.mks(к-во тактов, cpusp)
'возвращает к-во тактов с момента запуска процессора. Private Declare Function ReadTime Lib "user32" Alias "CallWindowProcA" (ByVal ptrMC As Long, ByVal P1 As Long, ByVal P2 As Long, ByVal P3 As Long, ByVal P4 As Long) As Long Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private BinCode(2) As Byte Private BinCode1(25) As Byte Private ptrMC As Long Private ptrMC1 As Long Private m_overhead As Long Private m_startcycle As Long
Private Sub Class_Initialize() BinCode(0) = &HF BinCode(1) = &H31 BinCode(2) = &HC3 ptrMC = VarPtr(BinCode(0)) 'учтем время, потраченное на выполнение ф-ции ReadTime StartTime m_overhead = StopTime End Sub
Sub StartTime() m_startcycle = ReadTime(ptrMC, 0, 0, 0, 0) End Sub
Function StopTime() As Long StopTime = ReadTime(ptrMC, 0, 0, 0, 0) - m_startcycle - m_overhead End Function
Function CpuSpeed() As Long m_startcycle = ReadTime(ptrMC, 0, 0, 0, 0) Sleep (1000) On Error Resume Next CpuSpeed = (ReadTime(ptrMC, 0, 0, 0, 0) - m_startcycle - m_overhead) / 100000 End Function
Function mks(ByVal cycles As Long, ByVal CpuSpeed As Long) As Long If CpuSpeed = 0 Then Exit Function On Error Resume Next 'возвращает к-во микросекунд mks = cycles * 10000 / CpuSpeed / 1000 End Function
Function ns(ByVal cycles As Long, ByVal CpuSpeed As Long) As Long If CpuSpeed = 0 Then Exit Function On Error Resume Next 'возвращает к-во наносекунд ns = cycles * 10000 / CpuSpeed End Function
| |