记录 Lotusscript 代码运行的时间

在分析 Lotusscript 性能时,我们经常需要找到耗时最长的瓶颈点,然后再进行针对性的优化。这时最常用的工具是代理性能简要表,但它有个限制是只能记录 Domino 相关对象方法的运行时间,比如 db.getView、view.getAllDocumentsByKey 等,对于原生 Lotusscript 的语句无法记录。

这时我们就需要将代码打成各个片段,记录每个片段的运行时间以缩小范围、进而定位到性能瓶颈的几条语句。但是 Lotusscript 中的 Now 只能精确到秒,显然是不够用的。还好通过 getThreadInfo 我们可以获取到毫秒级的时间值,具体代码如下:

Dim startTic As Long
Dim seconds As Double

startTic = Getthreadinfo(6)
seconds = (Getthreadinfo(6) – startTic) / Getthreadinfo(7)

msgbox “Finished. The code ran for ” & seconds & ” seconds.”

3 评论

  1. This also gives us a way to find out if we are running under the debugger:
    in an Initialize block use:
    Sub Initialize
    Dim tmStart!
    tmStart = Timer
    Stop
    noDebug = ((Timer – tmStart) <= 0.1)
    End Sub ' Initialize

    when debugger is active, it breaks on the Stop statemennt. The resolution of the timer is sufficient to determine that even if you are really fast hitting the F5 – Continue button, the global variable will be set to wether the Debugger is active or not.

  2. Hey there, I noticed your comment in OpenNTF at the JSON page. I built a new version of the JSON classes, they now parse abot 150.000 JSON characters per second, so the example JSON is parsed into an object ready for consumption in 100 msec, or 0,1 seconds. If you are interested I”ll send you a copy immedeately, otherwise I’ll post it to OpenNTF in the near future. Just thought you might like it.