Sub Timer_Test()
Dim counter as Long
Dim dTime as Double
dTime = Timer
For counter = 1 to 10000 ' Or whatever value you deem appropriate...
Call Relevant_Sub_or_Function_One
DoEvents 'optional, keeps Excel from crashing, but you shouldn't attempt to use Excel while this is running, or the results will be skewed...
Next counter
Debug.Print "descriptive text (method One)" & Timer - dTime
dTime = Timer
For counter = 1 to 10000 ' Or whatever value you deem appropriate...
Call Relevant_Sub_or_Function_Two
DoEvents 'optional, keeps Excel from crashing, but you shouldn't attempt to use Excel while this is running, or the results will be skewed...
Next counter
Debug.Print "descriptive text (method Two)" & Timer - dTime
End Sub
1 回答
我需要很长时间才能设置自己的示例数据和代码来测试任一选项的时间;但是(假设您已经获得了两个选项的代码),在您的结尾获取该信息应该相当简单 .
创建一个调用子(见下文),打开即时窗口,然后运行调用子查看结果 .
如果两种方法运行得太快而结果没有帮助,请设置如下所示的循环 . (注意:如果方法需要一段时间,你应该从一个较小的循环数开始,比如100左右,并根据需要进行构建)