Search code examples
openedgeprogress-4glprogress-db

Time taken to run a loop (Progress 4GL)


I wrote a query which contains multiple for each statements. The query is taking more than 20 minutes to fetch the data. Is there a way to check what time each loop started and ended. (How much time does each loop takes to execute and also the total time taken to complete the program).


Solution

  • Using ETIME you can initiate a counter of milliseconds. It could be called once or several times to tell how much time has passed since reset.

    ETIME(TRUE).
    
    /*
    Loop is here but instead I'll insert a small pause.
    */
    PAUSE 0.5.
    
    MESSAGE "This took" ETIME "milliseconds" VIEW-AS ALERT-BOX.
    

    Milliseconds might not be useful when dealing with several minutes. Then you can use TIME to keep track of seconds but you need to handle start time yourself then.

    DEFINE VARIABLE iStart AS INTEGER NO-UNDO.
    
    iStart = TIME.
    
    /*
    Loop is here but instead I'll insert a slightly longer pause.
    */
    PAUSE 2.
    
    MESSAGE "This took" TIME - iStart "seconds" VIEW-AS ALERT-BOX.
    

    If you want to keep track of several times then it might be better to output to a log file instead of using a MESSAGE-box that will stop execution until it's clicked.

    DEFINE VARIABLE i AS INTEGER NO-UNDO.
    DEFINE STREAM str.    
    OUTPUT STREAM str TO c:\temp\timing.txt.
    
    ETIME(TRUE).
    /*
    Fake loop
    */
    DO i = 1 TO 20:
        PAUSE 0.1.
        PUT STREAM str UNFORMATTED "Timing no " i " " ETIME "ms" SKIP.
    END.
    OUTPUT CLOSE.