猿问
回到首页
个人中心
反馈问题
注册登录
下载APP
首页
课程
实战
体系课
手记
专栏
慕课教程
你如何测试VBA代码的运行时间?
你如何测试VBA代码的运行时间?
在VBA中是否有代码可以包装一个函数,让我知道它运行的时间,以便我可以比较函数的不同运行时间?
海绵宝宝撒
浏览 2714
回答 3
3回答
慕田峪7331174
除非你的功能很慢,否则你需要一个非常高分辨率的计时器。我所知道的最准确的是QueryPerformanceCounter。谷歌更多信息。尝试推下到一个类,把它CTimer说,那么你可以让一个实例全球某处,只是打电话.StartCounter和.TimeElapsedOption ExplicitPrivate Type LARGE_INTEGER lowpart As Long highpart As LongEnd TypePrivate Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As LongPrivate Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As LongPrivate m_CounterStart As LARGE_INTEGERPrivate m_CounterEnd As LARGE_INTEGERPrivate m_crFrequency As DoublePrivate Const TWO_32 = 4294967296# ' = 256# * 256# * 256# * 256#Private Function LI2Double(LI As LARGE_INTEGER) As DoubleDim Low As Double Low = LI.lowpart If Low < 0 Then Low = Low + TWO_32 End If LI2Double = LI.highpart * TWO_32 + LowEnd FunctionPrivate Sub Class_Initialize()Dim PerfFrequency As LARGE_INTEGER QueryPerformanceFrequency PerfFrequency m_crFrequency = LI2Double(PerfFrequency)End SubPublic Sub StartCounter() QueryPerformanceCounter m_CounterStartEnd SubProperty Get TimeElapsed() As DoubleDim crStart As DoubleDim crStop As Double QueryPerformanceCounter m_CounterEnd crStart = LI2Double(m_CounterStart) crStop = LI2Double(m_CounterEnd) TimeElapsed = 1000# * (crStop - crStart) / m_crFrequencyEnd Property
0
0
0
catspeake
VBA中的定时器功能为您提供从午夜到1/100秒的经过秒数。Dim t as singlet = Timer'codeMsgBox Timer - t
0
0
0
打开App,查看更多内容
随时随地看视频
慕课网APP
相关分类
源码
spark分组排序提取前N个值
1 回答
请问转让门店小程序需要源码吗?门店小程序有自己的源代码吗?是否要注册计算机软件著作权才可以交易?
1 回答
算法与数据结构
数据结构中,与所使用的计算机无关的数据是什么?
1 回答
学完C语言之后是先学数据结构还是先学JAVA好呢?
1 回答
继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续