Home > Domino Tips > Developer > LotusScript > Optimize performance of your LotusScript code
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Optimize performance of your LotusScript code


Jens Gross
06.15.2004
Rating: -2.69- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

Ever wondered where the bottleneck is that makes you code so darn slow? With the lsTimer class below, you can easily pinpoint any time-consuming method, property, event, agent or any other piece of LotusScript code.

Whenever you want to measure more than one method in the same scope, make the lsTimer class global.

Global (Whatever)
    Options:
 Option Public
 Use "class.tools.lstimer"

    Declaration:
 Dim ticker as lstimer

    Initialize:
 Sub Initialize
  Set ticker = New lsTimer()
 End Sub
End Global

Public Function myFunction()
    Call ticker.start()
 ' your code goes here
    Call ticker.stop()
    Call ticker.out(Lsi_info(12), True)
End function 
  
Code: %REM
Create a smart icon with the 
@functions below to easily toggle
 the lsTimer 
mode on and off.

@If(@Environment("UserlsTimerMode")
= "0";
@Do(
@Environment("UserlsTimerMode";"1");
@Prompt([OK];"lsTimer ON";"lsTimer 
is now ON"));
@Do(
@Environment("UserlsTimerMode";"0");
@Prompt([OK];"lsTimer OFF";"lsTimer
 is now OFF")))
%END REM

' include lsconst & lserr.
%INCLUDE "lsconst.lss"
%INCLUDE "lserr.lss"

Type recTicks
 startTick As Single
 stopTick As Single
 mode As Integer
End Type
''
Private Const LIB_PACKAGE = 
"class.tools.lstimer"
'' Class to measure execution time of 
methods and properties in a LotusScript
library.
' @see class.tools.debug
Public Class lstimer
 Private s As notessession
 Private status As Integer
 Private ticker List As recTicks
 Private tmpTick As Single
 
'' Construct new instance
' @param None
 Public Sub new()
  Set s = New notessession
  status = ( s.getEnvironmentString
( "UserlsTimerMode" ) = "1" )
 End Sub
 
'' Class destructor
' @param None
 Public Sub delete()
  Erase ticker
 End Sub
 
'' Start a new timer for the calling method
' @return Allways returns True 
' @see stop 
 Public Function start() As Integer
  Me.start = True
  ticker(Lsi_info(12)).mode = True
  ticker(Lsi_info(12)).stopTick = 0
  ticker(Lsi_info(12)).startTick =  
Getthreadinfo
(LSI_THREAD_TICKS)
 End Function
 
''Stop timer function for the calling method. 
Stop() must be called prior 
to calling the out() method. 
'@return True if selected timer was 
stopped successfully otherwise return 
False
'@see start 
 Public Function stop() As Integer
  tmpTick = Getthreadinfo(LSI_THREAD_TICKS)
  If ( Iselement(ticker(Lsi_info(12))) = True ) Then
   tmpTick = tmpTick - ticker(Lsi_info(12)).startTick
   ticker(Lsi_info(12)).stopTick = ticker(Lsi_info
(12)).stopTick + tmpTick
   ticker(Lsi_info(12)).mode = False'
   Me.stop = True 
  End If 
 End Function
 
''Resume a previous stopped timer 
function for the calling method 
'@return True if resumed successfully 
otherwise return False
'@see stop 
 Public Function resume() As Integer
  tmpTick = Getthreadinfo
(LSI_THREAD_TICKS)
  If ( Iselement(ticker(Lsi_info(12))) = True ) 
Then
   ticker(Lsi_info(12)).mode = True
   ticker(Lsi_info(12)).startTick =  tmpTick
   Me.resume = True
  End If
 End Function 
 
''Print the total execution time for the 
calling method
'@param argREF The name of the calling 
method ( use Lsi_info(12) )
'@param argMode If True the execution time 
is calculated in seconds otherwise 
it is calculated in ticks  
'@return True if output was successfully 
otherwise return False if the timer 
for the calling method is running
'@see stop
 Public Function out(Byval argREF 
As String, argMode As Integer) As 
Integer
  If Not  ( Status = True ) Then Exit Function
  
  If ( Iselement(ticker(Lsi_info(12))) = True ) 
Then
   out = True
   If ( ticker(Lsi_info(12)).mode = True ) Then
    Print "ticker: " & Lsi_info(12) & " is running"
    out = False
    Exit Function
   End If
   
   If ( argMode = True ) Then
    Dim secs As Single
    secs = ticker(Lsi_info(12)).stopTick / 
ticksPerSecs()
    Print "ticker:" & Lsi_info(12) & ":" argREF
& "( " & Cstr(secs)  & " sec)"
   Else
    Print "ticker:" & Lsi_info(12) & ":" argREF
& "( " & Cstr(ticker(Lsi_info(12)).stopTick)  
& " tick)"
   End If 
  End If
 End Function
 
'' Erase timer for calling methods
'@return True if timer was successfully 
erased otherwise return False
 Public Function erase() As Integer
  If ( ticker(Lsi_info(12)).mode = True ) 
Then
   Print "ticker: " & Lsi_info(12) & " is 
running, could 
not erase timer"
   Me.erase = False
   Exit Function
  Else
   Erase ticker
   Me.erase = True
  End If
 End Function
 
'---Private methods ---  
 Private Function ticksPerSecs() 
As Integer
  ticksPerSecs = Getthreadinfo
(LSI_THREAD_TICKS_PER_SEC)
 End Function
End Class

MEMBER FEEDBACK TO THIS TIP

This system would appear to be an incredibly complex way of determining execution time. I use the following three lines of code:

Dim start as Double 
start = Timer() 
' your code goes here
Print ( Timer() - start ) 

The Timer function is accurate to 1/100 of a second. Anything shorter than that would be unapparent to the user and therefore not worth measuring. Multiple measurement points may be calculated by adding other double variables as needed.

What are the advantages, if any, of using Jens Nielsen's method?

—Jack S.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Jens Nielsen. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

Lotus Notes Domino Performance
Domino Domain Monitoring hints and gotchas
Using Domino Administrator to manage client settings
Build your own Domino multi-server test environment
How the Agent Profiler tool improves Notes/Domino performance
Benefits of virtualizing Lotus Domino servers
Configuring Domino Domain Monitoring (DDM)
How to move Notes databases off Domino 8 servers and save disk space
What is Notes 8.5's DAOS (Domino Attachment and Object Storage) feature?
Domino server setting and email policy tricks admins must know
Top 10 Lotus Notes/Domino administration tips of 2008

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts