VB6高精度计时类模块

VB6高精度计时类模块,第1张

概述创建一个类模块,粘贴如下代码: '大整数结构体Private Type LARGE_INTEGER LowPart As Long HighPart As LongEnd Type'获取时间计数器计数值Private Declare Function QueryPerformanceCounter _ Lib "kernel32" (l

创建一个类模块,粘贴如下代码:

'大整数结构体Private Type LARGE_INTEGER    LowPart As Long    HighPart As LongEnd Type'获取时间计数器计数值Private Declare Function queryPerformanceCounter _                lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long'获取震动频率:一个大整数Private Declare Function queryPerformanceFrequency _                lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long'用于将大整数的字节复制到Currency类型,完成转换的工作Private Declare Sub copyMemory _                lib "kernel32.dll" _                Alias "RtlMoveMemory" (Destination As Any,_                                       Source As Any,_                                       ByVal Length As Long)'初始时间Private initTime  As LARGE_INTEGER'每秒震动次数Private freqCount As LARGE_INTEGER'采样时振动器震动计数值Private logTime   As LARGE_INTEGER'每秒震动次数的Currency类型数据Private fFreq     As Currency'将一个长整型转换成高精度型数据Private Function LargeIntToCurrency(liinput As LARGE_INTEGER) As Currency    copyMemory LargeIntToCurrency,liinput,LenB(liinput)    LargeIntToCurrency = LargeIntToCurrency * 10000End Function'类初始化Private Sub Class_Initialize()    '获取振荡器的震荡频率    If queryPerformanceFrequency(freqCount) > 0 Then        If queryPerformanceCounter(initTime) > 0 Then        Else            Err.Raise 11,"记录震荡次数出错!"        End If    Else        Err.Raise 11,"读取震荡频率出错!"    End If    fFreq = LargeIntToCurrency(freqCount)End Sub'重置计数器Public Sub ReInit()    Call Class_InitializeEnd Sub'重置计数器,并返回从上次重置计数器开始共流失的秒数。Public Function ReInitGet() As Currency    Dim cuStart As Currency    Dim cuEnd   As Currency    queryPerformanceCounter logTime    cuStart = LargeIntToCurrency(initTime)    cuEnd = LargeIntToCurrency(logTime)    ReInitGet = (cuEnd - cuStart) / fFreq    queryPerformanceCounter initTimeEnd Function'返回从上次重置计数器开始共流失的秒数,但不重置计数器Public Function SmoothGet() As Currency    Dim cuStart As Currency    Dim cuEnd   As Currency    queryPerformanceCounter logTime    cuStart = LargeIntToCurrency(initTime)    cuEnd = LargeIntToCurrency(logTime)    SmoothGet = (cuEnd - cuStart) / fFreqEnd Function
该类可用于程序执行过程中的代码优化。因为它可以帮你了解某个函数中各个步骤区间的耗时。 总结

以上是内存溢出为你收集整理的VB6高精度计时类模块全部内容,希望文章能够帮你解决VB6高精度计时类模块所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1271294.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存